home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / devs / new8n1 / 8n1_040.s < prev    next >
Text File  |  1980-12-01  |  65KB  |  2,121 lines

  1. ********************************************************************************
  2. **                                          **
  3. **  Name       : 8n1_040.s                              **
  4. **  Copyright  : © Copyright 96-97                          **
  5. **  Author     : Iain Barclay                              **
  6. **  Created    : 15 Jul 97                              **
  7. **  Version    : 43.3                                  **
  8. **                                          **
  9. ********************************************************************************
  10.      ;
  11.      ;      SNMA specific options
  12.      ;
  13.      IFD      SNMA
  14.      ;
  15.      CPU      M68040
  16.      ;
  17.      SNMAOPT  Q,A,M,T,E-,P,R,B
  18.      ;
  19.      ELSE
  20.      IFD PHXASS
  21.      machine 68040
  22.      FPU
  23.      ENDC
  24.      ENDC
  25.      ;
  26.      ;
  27. NEWCODE  SET      1
  28. SETDSR     SET      0
  29. NCOMM     SET      0
  30. FASTVBR  SET      1
  31. DANGER     SET      0
  32. NEGCHECK SET      1
  33. EOFCODE  SET      1
  34.      ;
  35.      ;
  36.      ;
  37.      SECTION  text,CODE
  38.      ;
  39.      ;
  40.      ;
  41. DEVICES_SERIAL_I_OBSOLETE  EQU        1
  42.      ;
  43.      ;
  44.      ;
  45.      INCLUDE  "exec/lists.i"
  46.      INCLUDE  "exec/memory.i"
  47.      INCLUDE  "exec/resident.i"
  48.      INCLUDE  "exec/devices.i"
  49.      INCLUDE  "exec/execbase.i"
  50.      INCLUDE  "exec/io.i"
  51.      INCLUDE  "exec/ports.i"
  52.      INCLUDE  "exec/errors.i"
  53.      INCLUDE  "exec/initializers.i"
  54.      INCLUDE  "intuition/preferences.i"
  55.      INCLUDE  "devices/timer.i"
  56.      INCLUDE  "devices/serial.i"
  57.      INCLUDE  "hardware/custom.i"
  58.      INCLUDE  "hardware/cia.i"
  59.      INCLUDE  "hardware/intbits.i"
  60.      INCLUDE  "hardware/adkbits.i"
  61.      INCLUDE  "resources/misc.i"
  62.      INCLUDE  "exec/alerts.i"
  63.      INCLUDE  "exec/macros.i"
  64.      INCLUDE  "8n1.device_rev.i"
  65.      ;
  66.      ;      Define hardware references
  67.      ;
  68.      XREF      _custom
  69.      XREF      _intena,_intenar,_intreq,_intreqr
  70.      XREF      _ciab,_ciabpra
  71.      XREF      _serper,_serdat,_serdatr
  72.      XREF      _adkcon,_adkconr
  73.      ;
  74.      ;      Exec Functions
  75.      ;
  76.      XREF      _LVORemDevice,_LVOOpenDevice,_LVOCloseDevice
  77.      XREF      _LVOSupervisor
  78.      XREF      _LVOAllocMem,_LVOFreeMem,_LVOCopyMem,_LVOTypeOfMem
  79.      XREF      _LVOReplyMsg
  80.      XREF      _LVOSendIO,_LVOAbortIO
  81.      XREF      _LVODisable,_LVOEnable
  82.      XREF      _LVOFindName
  83.      XREF      _LVOOpenResource
  84.      XREF      _LVOAddIntServer,_LVORemIntServer
  85.      XREF      _LVOAlert
  86.      XREF      _LVOOpenLibrary,_LVOCloseLibrary
  87.      XREF      _LVOCacheClearU
  88.      ;
  89.      ;      Misc Resource Functions
  90.      ;
  91.      XREF      _LVOAllocMiscResource,_LVOFreeMiscResource
  92.      ;
  93.      ;      Intuition Functions
  94.      ;
  95.      XREF      _LVOGetPrefs
  96.      ;
  97.      ;      Mask used to get rid of the printer bits.
  98.      ;
  99. PRTMASK  EQU      (CIAF_PRTRPOUT|CIAF_PRTRBUSY)
  100.      ;
  101.      ;      Autovector offsets
  102.      ;
  103. LVL1VEC  EQU      (1-1)*4+$64
  104. LVL5VEC  EQU      (5-1)*4+$64
  105. VBR_SIZE EQU      $400
  106. custom     EQU      $dff000
  107. ciab     EQU      $bfd000
  108.      ;
  109.      ;  New Style device stuff (not the best way but it will have to do for now)
  110.      ;  If u don't have New Style stuff defined elsewhere remove these ;
  111. ;NSCMD_DEVICEQUERY   EQU $4000
  112. ; STRUCTURE  NSDEVICEQUERYRESULT,0
  113. ;    ULONG   DEVQUERYFORMAT
  114. ;    ULONG   SIZEAVAILABLE
  115. ;    UWORD   DEVICETYPE
  116. ;    UWORD   DEVICESUBTYPE
  117. ;    APTR    SUPPORTEDCOMMANDS
  118. ;    LABEL   NSDEVICEQUERYRESULT_SIZE
  119. ;NSDEVTYPE_SERIAL    EQU 11
  120.      ;
  121.      ;      Device base
  122.      ;
  123.      STRUCTURE Base8n1,LIB_SIZE
  124.      UBYTE      vb_pad1
  125.      UBYTE      vb_pad2
  126.      ULONG      vb_SaveDDRA
  127.      ULONG      vb_SavePRA
  128.      APTR      vb_MiscBase
  129.      APTR      vb_OldLevel1
  130.      APTR      vb_OldLevel5
  131.      ULONG      vb_SegList
  132.      ULONG      vb_DefBaud
  133.      ULONG      vb_DefRBufLen
  134.      ULONG      vb_CurRBuf
  135.      ULONG      vb_CurRBufLen
  136.      ULONG      vb_CurBaud
  137.      ULONG      vb_SerFlags
  138.      ULONG      vb_Initialized
  139.      LABEL      sizeof_Base8n1
  140.      ;
  141.      ;
  142.      ;
  143. Start:
  144.      moveq      #-1,d0                  ; set return code
  145.      rts                          ; return
  146.      ;
  147.      ;      RamLib looks for this romtag
  148.      ;
  149. ROMTag     DC.W      RTC_MATCHWORD               ; RT_MATCHWORD
  150.      DC.L      ROMTag                  ; RT_MATCHTAG
  151.      DC.L      ENDTag                  ; RT_ENDSKIP
  152.      DC.B      RTF_AUTOINIT                  ; RT_FLAGS
  153.      DC.B      VERSION                  ; RT_VERSION
  154.      DC.B      NT_DEVICE                  ; RT_TYPE
  155.      DC.B      0                      ; RT_PRI
  156.      DC.L      Name                      ; RT_NAME
  157.      DC.L      IdString                  ; RT_IDSTRING
  158.      DC.L      Init                      ; RT_INIT
  159.      ;
  160.      ;      Perform device initialization
  161.      ;
  162.     cnop 0,8    ; align for 040+
  163. InitRoutine:
  164.      exg      d0,a0                   ; swap seglist and base
  165.      move.l   d0,vb_SegList(a0)              ; store seglist in base
  166.      move.l   a6,SysBase                  ; store in global storage
  167.      exg      a0,d0                   ; swap them back
  168.      rts                          ; return
  169.      ;
  170.      ;
  171.      ;
  172.     cnop 0,8 ; align for 040+
  173. dev_Open:   ; (a1 iorequest, a5 will be Base8n1, a6 sysbase )
  174.      addq.w   #1,LIB_OPENCNT(a6)              ; fake open so device is not expunged
  175.      move.l   a5,-(sp)                  ; save registers
  176.      move.l   a6,a5                   ; save base
  177.      ;
  178.      cmpi.w   #IOEXTSER_SIZE,MN_LENGTH(a1)          ; IORequest size >= IOEXTSER_SIZE
  179.      bcs.w      50$                      ; nope, finish
  180.      ;
  181.      tst.l      d0                      ; unit 0 specified?
  182.      bne.w      50$                      ; nope, error (who cares?)
  183.      ;
  184.      cmpi.w   #1,LIB_OPENCNT(a5)              ; currently open?
  185.      bne.w      10$                      ; yep, go process
  186.      ;
  187.      move.l   IO_READLEN(a1),vb_SerFlags(a5)      ; save flags
  188.      ;
  189.      tst.l      vb_Initialized(a5)              ; already initialized?
  190.      bne.w      40$                      ; yep, skip initialization
  191.      ;
  192.      move.l   SysBase(pc),a6              ; get ExecBase
  193.      move.l   a1,-(sp)                  ; save register
  194.      ;
  195.      lea      miscresource(pc),a1              ; ptr to resource name
  196.      jsr      _LVOOpenResource(a6)              ; go open it
  197.      move.l   d0,vb_MiscBase(a5)              ; save base
  198.      ;
  199.      moveq      #MR_SERIALPORT,d0              ; set unit number
  200.      bsr.w      allocResource               ; go allocate it
  201.      tst.l      d0                      ; did we get it?
  202.      bne.b      20$                      ; nope, error
  203.      ;
  204.      moveq      #MR_SERIALBITS,d0              ; set unit number
  205.      bsr.w      allocResource               ; go allocate it
  206.      tst.l      d0                      ; did we get it?
  207.      bne.b      5$                      ; nope, error
  208.      ;
  209.      ;
  210.      ;      Get system preferences
  211.      ;
  212.      lea      intuitlib(pc),a1              ; ptr to library name
  213.      moveq      #0,d0                   ; can't use OldOpenLibrary as this will not be supported.
  214.      jsr      _LVOOpenLibrary(a6)              ; go open it (any version)
  215.      move.l   d0,a6                   ; get intuition base
  216.      ;
  217.      move.l   #(pf_SerParShk+3)&$fffffffc,d0      ; size we need (aligned)
  218.      suba.l   d0,sp                   ; reserve space
  219.      ;
  220.      move.l   sp,a0                   ; set data area ptr
  221.      jsr      _LVOGetPrefs(a6)              ; get preferences
  222.      ;
  223.      move.l   a6,a1                   ; get intuition base
  224.      move.l   SysBase(pc),a6              ; restore ExecBase
  225.      jsr      _LVOCloseLibrary(a6)              ; close it
  226.      ;
  227.      moveq      #$0f,d0                  ; set mask
  228.      and.b      pf_SerStopBuf(sp),d0              ; get bufsize index
  229.      moveq      #0,d1                   ; clear upper half
  230.      addq.l   #8,d0                   ; calc shift value
  231.      move.w   pf_BaudRate(sp),d1              ; get baud rate
  232.      lsl.l      #2,d0                   ; get default bufsize
  233.      move.l   d0,vb_DefRBufLen(a5)              ; and store
  234.     IFNE NEWCODE
  235.      move.l   .baudTable(pc,d1.l*4),d1          ; get baud rate
  236.     ELSE
  237.      move.w   .baudTable(pc,d1.l*2),d1          ; get baud rate
  238.     ENDC
  239.      ;
  240.      move.l   d1,vb_DefBaud(a5)              ; and store
  241.      ;
  242.      bsr      internalReset               ; go init baud and buffer
  243.      ;
  244.      lea      (pf_SerParShk+3)&$fffffffc(sp),sp   ; restore stack
  245.      tst.l      d0                      ; got 'em?
  246.      beq.b      30$                      ; yep, branch
  247.      ;
  248.      moveq      #MR_SERIALBITS,d0              ; set unit
  249.      move.l   vb_MiscBase(a5),a6              ; get MiscBase
  250.      jsr      _LVOFreeMiscResource(a6)          ; release the resource
  251.      ;
  252. 5$     moveq      #MR_SERIALPORT,d0              ; set unit
  253.      move.l   vb_MiscBase(a5),a6              ; get MiscBase
  254.      jsr      _LVOFreeMiscResource(a6)          ; release the resource
  255.      ;
  256. 20$     moveq      #SerErr_DevBusy,d0              ; set error status
  257.      move.l   (sp)+,a1                  ; restore register
  258.      bra      50$                      ; go return
  259.      ;
  260.      ;      Preferences baud lookup table
  261.      ;
  262.      cnop 0,8 ; align for 040+
  263.     IFNE NEWCODE
  264. .baudTable
  265.      dc.l      112,300,1200,2400,4800,9600,19200,31250,38400,57600,62400,64800
  266.      dc.l      76800,115200
  267.     ELSE
  268. .baudTable
  269.      dc.w      112,300,1200,2400,4800,9600,19200,31250,38400,57600,62400,64800
  270.     ENDC
  271.      ;
  272.      cnop 0,8 ; align for 040+
  273. 30$     moveq      #0,d1                   ; clear flags
  274.      lea      timerReq(pc),a1              ; ptr to timer request
  275.      moveq      #UNIT_VBLANK,d0              ; set unit
  276.      lea      timerdevice(pc),a0              ; ptr to device name
  277.      jsr      _LVOOpenDevice(a6)              ; go open it
  278.      ;
  279.     IFNE DANGER
  280.      move.w   #$04000,_intena
  281.      addq.b   #1,IDNestCnt(a6)              ; disable interrupts
  282.     ELSE
  283.      jsr      _LVODisable(a6)              ; disable interrupts
  284.     ENDC
  285.      ;
  286.      move.l   #ciab,a1                  ; get ptr to ciab
  287.      move.b   ciaddra(a1),d0
  288.      move.l   d0,vb_SaveDDRA(a5)              ; save DDR value
  289.      andi.b   #PRTMASK,d0                  ; make serial bits input
  290.      move.b   (a1),d1                  ; ciapra(a1)
  291.      ori.b      #CIAF_COMDTR|CIAF_COMRTS,d0          ; make DTR/RTS output
  292.      move.l   d1,vb_SavePRA(a5)              ; save PR value
  293.      andi.b   #CIAF_COMDTR|CIAF_COMRTS|PRTMASK,d0 ; turn on DTR/RTS
  294.      move.b   d0,ciaddra(a1)
  295.      andi.b   #CIAF_COMCTS|CIAF_COMDSR|PRTMASK,d1 ; make CTS/DSR input
  296.      move.b   d1,(a1)                  ; ciapra(a1)
  297.      ;
  298.      moveq      #INTB_PORTS,d0              ; get interrupt number
  299.      lea      VBInterrupt(pc),a1              ; get interrupt ptr
  300.      jsr      _LVOAddIntServer(a6)              ; add it to the list
  301.      ;
  302.      bsr      getVBR                  ; get vector base (in A0)
  303.      ;
  304.     IFNE FASTVBR
  305.      move.l   a5,-(sp)                  ; save a5
  306.      move.l   a0,-(sp)                  ; save VBR
  307.      move.l   a0,a1
  308.      jsr      _LVOTypeOfMem(a6)
  309.      btst      #MEMB_FAST,d0               ; VBR in fast?
  310.      bne.b      nofast$                  ; yep, branch
  311.      move.l   #VBR_SIZE,d0
  312.      moveq      #MEMF_PUBLIC|MEMF_FAST,d1
  313.      jsr      _LVOAllocMem(a6)              ; Alloc fast-ram for VBR
  314.      tst.l      d0
  315.      beq.b      nofast$                  ; no fast, branch
  316.      move.l   (sp),a0                  ; get VBR
  317.      move.l   d0,a1
  318.      move.l   d0,-(sp)                  ; save new VBR
  319.      move.l   #VBR_SIZE,d0
  320.      jsr      _LVOCopyMem(a6)
  321.      move.l   (sp)+,a0                  ; get new VBR
  322.      lea      setVBR$(pc),a5
  323.      jsr      _LVOSupervisor(a6)              ; set new VBR
  324.      jsr      _LVOCacheClearU(a6)              ; clear cache
  325.      move.l   (sp)+,d0                  ; was old VBR zero?
  326.      beq.b      waszero$                  ; yep, branch (don't free)
  327.      move.l   d0,a1
  328.      move.l   #VBR_SIZE,d0
  329.      jsr      _LVOFreeMem(a6)
  330. waszero$
  331.      bsr      getVBR
  332.      bra.b      vbend$
  333.      cnop      0,8 ; align for 040+
  334. setVBR$
  335.      movec      a0,vbr                  ; set VBR
  336.      rte
  337.      cnop      0,8 ; align for 040+
  338. nofast$
  339.      move.l   (sp)+,a0                  ; restore VBR
  340. vbend$
  341.      move.l   (sp)+,a5                  ; restore a5
  342.     ENDC
  343.      move.l   LVL1VEC(a0),vb_OldLevel1(a5)          ; save original vector
  344.      lea      level1(pc),a1               ; get new vector ptr
  345.      move.l   a1,LVL1VEC(a0)              ; set new vector
  346.      ;
  347.      move.l   LVL5VEC(a0),vb_OldLevel5(a5)          ; save original vector
  348.      lea      level5(pc),a1               ; get new vector ptr
  349.      move.l   a1,LVL5VEC(a0)              ; set new vector
  350.      ;
  351.      move.l   #custom+intena,a1              ; get ptr to custom chips
  352.      move.w   #INTF_RBF|INTF_TBE,intreq-intena(a1); clear pending interrupts
  353.      move.w   #INTF_SETCLR|INTF_RBF|INTF_TBE,(a1) ; enable RBF & TBE
  354.      ;
  355.      addq.l   #1,vb_Initialized(a5)           ; set flag
  356.      ;
  357.     IFNE DANGER
  358.      subq.b   #1,IDNestCnt(a6)
  359.      bge.b      enable$
  360.      move.w   #$C000,(a1)                  ; enable interrupts
  361. enable$  move.l   (sp)+,a1                  ; restore register
  362.      bra.b      40$                      ; go exit
  363.     ELSE
  364.      move.l   (sp)+,a1                  ; restore register
  365.      ;
  366.      pea      40$(pc)
  367.      jmp      _LVOEnable(a6)              ; enable interrupts
  368.      ; go exit
  369.     ENDC
  370.      ;
  371.      cnop 0,8 ; align for 040+
  372. 10$     moveq      #SerErr_DevBusy,d0              ; preset error status
  373.      btst      #SERB_SHARED,vb_SerFlags+3(a5)      ; opened shared?
  374.      beq.b      50$                      ; nope, error
  375.      btst      #SERB_SHARED,IO_SERFLAGS(a1)          ; requesting shared?
  376.      beq.b      50$                      ; nope, error
  377.      ;
  378.      ;      Initialize I/O request
  379.      ;
  380. 40$     move.b   #8,IO_READLEN(a1)              ; set read length
  381.      move.b   #8,IO_WRITELEN(a1)              ; set write length
  382.      move.b   #1,IO_STOPBITS(a1)              ; set stop bits
  383.      move.b   IO_SERFLAGS(a1),d0
  384.      ori.b      #SERF_XDISABLED|SERF_RAD_BOOGIE|SERF_QUEUEDBRK|SERF_7WIRE,d0 ;flags
  385.      andi.b   #~(SERF_PARTY_ODD|SERF_PARTY_ON),d0 ; not used
  386.      move.b   d0,IO_SERFLAGS(a1)
  387.      move.l   vb_CurBaud(a5),IO_BAUD(a1)          ; set baud
  388.      moveq      #0,d0                   ; no error
  389.      move.l   vb_CurRBufLen(a5),IO_RBUFLEN(a1)    ; set read buffer length
  390.      ;
  391.      addq.w   #1,LIB_OPENCNT(a5)              ; incr open count
  392.      andi.b   #~(1<<LIBB_DELEXP),LIB_FLAGS(a5)    ; clear expunge bit
  393.      ;
  394. 50$     move.b   d0,IO_ERROR(a1)              ; store error code
  395.      move.l   a5,a6                   ; restore base
  396.      move.l   (sp)+,a5                  ; restore registers
  397.      move.l   (sp)+,a0
  398.      addq.w   #1,LIB_OPENCNT(a6)              ; remove fake open
  399.      jmp      (a0)                      ; return
  400.      ;
  401.      ;      Attempt to allocate one of the serial resources.
  402.      ;
  403.      cnop 0,8 ; align for 040+
  404. allocResource:
  405.      move.l   a6,-(sp)                  ; save base pointer
  406.      move.l   d0,-(sp)                  ; save unit
  407.      lea      Name(pc),a1                  ; get lock name
  408.      move.l   vb_MiscBase(a5),a6              ; get MiscBase
  409.      jsr      _LVOAllocMiscResource(a6)          ; go allocate it
  410.      tst.l      d0                      ; did we get it?
  411.      beq.b      20$                      ; yep, branch
  412.      ;
  413.      ;      It's in use, so we try to locate the device using the string
  414.      ;      returned and attempt to remove it.
  415.      ;
  416.      move.l   SysBase(pc),a6              ; get ExecBase
  417.      ;
  418.      move.l   d0,a1                   ; get ptr to serial name
  419.      lea      DeviceList(a6),a0              ; get ptr to device list
  420.      jsr      _LVOFindName(a6)              ; go find it
  421.      tst.l      d0                      ; found?
  422.      beq.b      10$                      ; nope, branch
  423.      ;
  424.      move.l   d0,a1                   ; xfer device ptr
  425.      jsr      _LVORemDevice(a6)              ; remove it
  426.      ;
  427.      ;      We then retry the allocate.
  428.      ;
  429. 10$     move.l   (sp),d0                  ; get unit
  430.      lea      Name(pc),a1                  ; get lock name
  431.      move.l   vb_MiscBase(a5),a6              ; get MiscBase
  432.      jsr      _LVOAllocMiscResource(a6)          ; go allocate it
  433.      ;
  434. 20$     addq.l   #4,sp                   ; restore stack ptr
  435.      move.l   (sp)+,a6                  ; restore base ptr
  436.      move.l   (sp)+,a0
  437.      jmp      (a0)                      ; return
  438.      ;
  439.      ;      Set exception vectors
  440.      ;
  441.      cnop 0,8 ; align for 040+
  442. getVBR:
  443.      move.l   a5,-(sp)                  ; save registers
  444.      lea      20$(pc),a5                  ; ptr to routine
  445.      jsr      _LVOSupervisor(a6)              ; get into supervisor state
  446. 10$     move.l   (sp)+,a5                  ; restore register
  447.      move.l   (sp)+,a1                  ; return
  448.      jmp      (a1)
  449.      cnop 0,8 ; align for 040+
  450. 20$     movec.l  vbr,a0                  ; get vector base
  451.      rte                          ; return
  452.      ;
  453.      ;      Device Close routine
  454.      ;
  455.      cnop 0,8 ; align for 040+
  456. dev_Close:
  457.      ;
  458.                               ; invalidate
  459.      move.l   #-1,IO_DEVICE(a1)              ;   device
  460.      ;
  461.      tst.w      LIB_OPENCNT(a6)
  462.      beq.b      5$
  463.      subq.w   #1,LIB_OPENCNT(a6)              ; decr open count
  464.      bne.w      dev_Null                  ; still open? yep, branch
  465. 5$
  466.      ;
  467.      move.l   a5,-(sp)                  ; save registers
  468.      move.l   a6,a5                   ; save base
  469.      move.l   SysBase(pc),a6              ; get ExecBase
  470.      ;
  471.      move.l   a1,-(sp)                  ; save registers
  472.      ;
  473.      bsr.b      getVBR                  ; get vector base (in A0)
  474.      ;
  475.      moveq      #1,d0                   ; set not restored code
  476.      ;
  477.      lea      level1(pc),a1               ; get our vector ptr
  478.      cmpa.l   LVL1VEC(a0),a1              ; do they match?
  479.      bne      10$                      ; nope, can't restore
  480.      ;
  481.      lea      level5(pc),a1               ; get our vector ptr
  482.      cmpa.l   LVL5VEC(a0),a1              ; do they match?
  483.      bne      10$                      ; nope, can't restore
  484.      ;
  485.     IFNE DANGER
  486.      move.w   #$04000,_intena
  487.      addq.b   #1,IDNestCnt(a6)              ; disable interrupts
  488.     ELSE
  489.      jsr      _LVODisable(a6)              ; disable interrupts
  490.     ENDC
  491.      ;
  492.      move.l   vb_OldLevel1(a5),LVL1VEC(a0)          ; restore original vector
  493.      move.l   vb_OldLevel5(a5),LVL5VEC(a0)          ; restore original vector
  494.      ;
  495.      moveq      #INTB_PORTS,d0              ; get interrupt number
  496.      lea      VBInterrupt(pc),a1              ; get interrupt ptr
  497.      jsr      _LVORemIntServer(a6)              ; remove it from the list
  498.      ;
  499.      move.l   #custom+intena,a0              ; get custom base
  500.      move.w   #INTF_RBF|INTF_TBE,d0           ; indicate serial interrupts
  501.      move.w   d0,(a0)                  ; disable interrupts
  502.      move.w   d0,intreq-intena(a0)              ; clear pending interrupts
  503.      ;
  504.      bsr      freeBuf                  ; free allocated buffers
  505.      ;
  506.      move.l   #ciab,a0                  ; get pointer to ciab
  507.      move.b   ciaddra(a0),d0              ; get DDR value
  508.      andi.b   #PRTMASK,d0                  ; save printer bits
  509.      ori.b      #~PRTMASK,d0                  ; set serial bits to output
  510.      move.b   d0,ciaddra(a0)              ; store value
  511.      ;
  512.      move.b   (a0),d0                  ; get PR value ( ciapra(a0) )
  513.      andi.b   #PRTMASK,d0                  ; mask out serial bits
  514.      move.l   vb_SavePRA(a5),d1              ; get saved value
  515.      andi.b   #~PRTMASK,d1                  ; mask out printer bits
  516.      or.b      d1,d0                   ; combine the two
  517.      move.b   d0,(a0)                  ; and store ( ciapra(a0) )
  518.      ;
  519.      move.b   ciaddra(a0),d0              ; get DDR value
  520.      andi.b   #PRTMASK,d0                  ; mask out serial bits
  521.      move.l   vb_SaveDDRA(a5),d1              ; get saved value
  522.      andi.b   #~PRTMASK,d1                  ; mask out printer bits
  523.      or.b      d1,d0                   ; combine the two
  524.      move.b   d0,ciaddra(a0)              ; and store
  525.      ;
  526.      lea      timerReq(pc),a1              ; get ptr to timer request
  527.      jsr      _LVOCloseDevice(a6)              ; go close it
  528.      ;
  529.      move.l   vb_MiscBase(a5),a6              ; get MiscBase
  530.      moveq      #MR_SERIALBITS,d0              ; set unit
  531.      jsr      _LVOFreeMiscResource(a6)          ; release the resource
  532.      ;
  533.      moveq      #MR_SERIALPORT,d0              ; set unit
  534.      jsr      _LVOFreeMiscResource(a6)          ; release the resource
  535.      move.l   SysBase(pc),a6              ; restore ExecBase
  536.      ;
  537.     IFNE DANGER
  538.      subq.b   #1,IDNestCnt(a6)
  539.      bge.b      enable$
  540.      move.w   #$C000,_intena              ; enable interrupts
  541. enable$
  542.     ELSE
  543.      jsr      _LVOEnable(a6)              ; enable interrupts
  544.     ENDC
  545.      ;
  546.      moveq      #0,d0                   ; free up everything
  547.      subq.l   #1,vb_Initialized(a5)           ; clear flag
  548.      ;
  549. 10$     move.l   (sp)+,a1                  ; restore registers
  550.      ;
  551.      move.l   a5,a6                   ; restore base
  552.      move.l   (sp)+,a5                  ; restore registers
  553.      ;
  554.      tst.l      d0                      ; freed?
  555.      bne.b      dev_Null                  ; nope, can't expunge, exit
  556.      ;
  557.      clr.l      vb_SerFlags(a6)              ; clear flags
  558.      ;
  559.      btst      #LIBB_DELEXP,LIB_FLAGS(a6)          ; delayed expunge set?
  560.      beq.b      dev_Null                  ; nope, go exit
  561.      ;
  562.      ;      Device Expunge routine (also fall through from dev_Close)
  563.      ;
  564. dev_Expunge:
  565.      ori.b      #1<<LIBB_DELEXP,LIB_FLAGS(a6)       ; Set expunge flag
  566.      tst.w      LIB_OPENCNT(a6)              ; currently open?
  567.      bne.b      dev_Null                  ; yep, so just exit
  568.      ;
  569.      move.l   vb_SegList(a6),d0              ; get seglist ptr
  570.      move.l   d0,-(sp)                  ; save registers (save D0!)
  571.      ;
  572.      move.l   a6,a1                   ; get base
  573.      ; This is the REMOVE macro
  574.      move.l   (a1)+,a0
  575.      move.l   (a1),a1
  576.      move.l   a0,(a1)
  577.      move.l   a1,LN_PRED(a0)
  578.      ;
  579.      move.l   a6,a1                   ; get base
  580.      moveq      #0,d0                   ; clear work
  581.      move.w   LIB_NEGSIZE(a6),d0              ; calculate
  582.      suba.l   d0,a1                   ;   memory address
  583.      add.w      LIB_POSSIZE(a6),d0              ;     and size
  584.      move.l   a6,-(sp)                  ; save registers
  585.      move.l   SysBase(pc),a6              ; get ExecBase
  586.      jsr      _LVOFreeMem(a6)              ; free it
  587.      ;
  588.      move.l   (sp)+,a6                  ; restore registers
  589.      move.l   (sp)+,d0                  ; restore registers
  590.      move.l   (sp)+,a0
  591.      jmp      (a0)                      ; return (seglist in D0!)
  592.      ;
  593.      ;      Device "ExtFunc" routine
  594.      ;
  595.      cnop 0,8 ; align for 040+
  596. dev_Null:
  597.      move.l   (sp)+,a0
  598.      moveq      #0,d0                   ; set return code
  599.      jmp      (a0)                      ; return
  600.      ;
  601.      ;
  602.      cnop 0,8 ; align for 040+
  603. cmdTable dc.l      cmd_Invalid-cmdTable              ; CMD_INVALID
  604.      dc.l      cmd_Reset-cmdTable              ; CMD_RESET
  605.      dc.l      cmd_Read-cmdTable              ; CMD_READ
  606.      dc.l      cmd_Write-cmdTable              ; CMD_WRITE
  607.      dc.l      cmd_Invalid-cmdTable              ; CMD_UPDATE
  608.      dc.l      cmd_Clear-cmdTable              ; CMD_CLEAR
  609.      dc.l      cmd_Invalid-cmdTable              ; CMD_STOP
  610.      dc.l      cmd_Invalid-cmdTable              ; CMD_START
  611.      dc.l      cmd_Flush-cmdTable              ; CMD_FLUSH
  612.      dc.l      sdcmd_Query-cmdTable              ; SDCMD_QUERY
  613.      dc.l      sdcmd_Break-cmdTable              ; SDCMD_BREAK
  614.      dc.l      sdcmd_SetParams-cmdTable          ; SDCMD_SETPARAMS
  615. endTable
  616.      dc.l      nscmd_DeviceQuery-cmdTable          ; NSCMD_DEVICEQUERY
  617. nsendTable
  618.      ;
  619.      ;      Device BeginIO routine
  620.      ;
  621.      cnop 0,8 ; align for 040+
  622. dev_BeginIO:
  623.      move.l   a5,-(sp)                  ; save register
  624.      move.l   a6,a5                   ; save base
  625.      move.l   SysBase(pc),a6              ; get ExecBase
  626.      ;
  627.      move.b   #NT_MESSAGE,LN_TYPE(a1)          ; set type
  628.      clr.b      IO_ERROR(a1)                  ; clear error
  629.      ;
  630.      andi.b   #~(IOSERF_QUEUED|IOSERF_ACTIVE),IO_FLAGS(a1) ; clear flags
  631.      ;
  632.      moveq      #0,d0
  633.      move.w   IO_COMMAND(a1),d0              ; get command
  634.      lsl.l      #2,d0                   ; multiply by 4
  635.      cmp.l      #endTable-cmdTable,d0           ; in range?
  636.      bcs.b      5$                      ; yep, branch
  637.      cmp.l      #(4*NSCMD_DEVICEQUERY),d0
  638.      bne.b      30$
  639.      moveq      #endTable-cmdTable,d0
  640.      ;
  641. 5$     move.l   cmdTable(pc,d0.l),d0              ; get routine offset
  642.      jsr      cmdTable(pc,d0.l)              ; go do it
  643.      tst.l      d0                      ; I/O completed?
  644.      bne.b      19$                      ; nope, go return
  645.      ;
  646. 10$
  647.      btst      #IOB_QUICK,IO_FLAGS(a1)          ; need to reply?
  648.      bne.b      20$                      ; nope, branch
  649. 15$     jsr      _LVOReplyMsg(a6)              ; send it back
  650.      ;
  651. 19$     andi.b   #~(1<<IOB_QUICK),IO_FLAGS(a1)       ; clear quick bit
  652. 20$     move.l   a5,a6                   ; restore base
  653.      move.l   (sp)+,a5                  ; restore register
  654.      move.l   (sp)+,a0
  655.      jmp      (a0)                      ; return
  656.      cnop 0,8 ; align for 040+
  657.      ;
  658. 30$     move.b   #IOERR_NOCMD,IO_ERROR(a1)          ; invalid command
  659.      bra.b      10$                      ; branch
  660.      ;
  661.      ;      Device AbortIO routine
  662.      ;
  663.      cnop 0,8 ; align for 040+
  664. dev_AbortIO:
  665.      move.l   a5,-(sp)                  ; save registers
  666.      move.l   a6,a5                   ; save base
  667.      move.l   SysBase(pc),a6              ; get ExecBase
  668.      ;
  669.     IFNE DANGER
  670.      move.w   #$04000,_intena
  671.      addq.b   #1,IDNestCnt(a6)              ; disable interrupts
  672.     ELSE
  673.      jsr      _LVODisable(a6)              ; disable interrupts
  674.     ENDC
  675.      ;
  676.      move.l   IO_COMMAND(a1),d1              ; get flags
  677.      btst      #IOSERB_QUEUED+8,d1              ; queued request?
  678.      bne.b      40$                      ; yep, branch
  679.      ;
  680.      btst      #IOSERB_ACTIVE+8,d1              ; active request?
  681.      beq.b      10$                      ; nope, just exit
  682.      ;
  683.      move.l   d1,d0                   ; get command
  684.      swap      d0
  685.      subq.w   #CMD_READ,d0                  ; was it a read?
  686.      beq.b      20$                      ; yep, go process
  687.      ;
  688.      subq.w   #CMD_WRITE-CMD_READ,d0          ; was it a write?
  689.      beq.b      30$                      ; yep, go process
  690.      ;
  691.      subq.w   #SDCMD_BREAK-CMD_WRITE,d0          ; was it a break?
  692.      beq.b      30$                      ; yep, go process
  693.      ;
  694.      ;      Fall through or enter from below
  695.      ;
  696.     IFNE DANGER
  697. 10$     subq.b   #1,IDNestCnt(a6)
  698.      bge.b      enable$
  699.      move.w   #$C000,_intena              ; enable interrupts
  700. enable$
  701.     ELSE
  702. 10$     jsr      _LVOEnable(a6)              ; enable ints and return
  703.     ENDC
  704. 15$     move.l   a5,a6                   ; restore base
  705.      move.l   (sp)+,a5                  ; restore registers
  706.      move.l   (sp)+,a0
  707.      jmp      (a0)                      ; return
  708.      ;
  709.      ;      Abort an active read request
  710.      ;
  711.      cnop 0,8 ; align for 040+
  712. 20$     clr.l      cr_IOReq                  ; no longer active
  713.      bra.b      50$                      ; go set flags
  714.      ;
  715.      ;      Abort an active write request
  716.      ;
  717.      cnop 0,8 ; align for 040+
  718. 30$     clr.l      cw_Length                  ; no longer active
  719.      clr.l      cw_IOReq                  ; no longer active
  720.      move.l   cw_Buffer(pc),d0              ; get buffer ptr
  721.      sub.l      IO_DATA(a1),d0              ; calc number of bytes xfer'd
  722.      move.l   d0,IO_ACTUAL(a1)              ; store
  723.      ;
  724.      ;      Force a TBE interrupt to get the next write going.
  725.      ;
  726.      move.w   #INTF_SETCLR|INTF_TBE,_intreq       ; make TBE pending
  727.      bra.b      50$                      ; go set flags
  728.      ;
  729.      ;      Remove I/O from queue.
  730.      ;
  731.      cnop 0,8 ; align for 040+
  732. 40$     move.l   a1,-(sp)                  ; save ptr
  733.      ; This is the REMOVE macro
  734.      move.l   (a1)+,a0
  735.      move.l   (a1),a1
  736.      move.l   a0,(a1)
  737.      move.l   a1,LN_PRED(a0)
  738.      ;
  739.      move.l   (sp)+,a1                  ; restore ptr
  740.      ;
  741.      ;      Set error and return I/O
  742.      ;
  743. 50$     move.b   #IOERR_ABORTED,IO_ERROR(a1)          ; set error code
  744.      move.b   IO_FLAGS(a1),d1              ; get flags
  745.      ori.b      #1<<IOSERB_ABORT,d1              ; set abort flag
  746.      andi.b   #~(IOSERF_QUEUED|IOSERF_ACTIVE),d1  ; clear flags
  747.      move.b   d1,IO_FLAGS(a1)              ; store flags
  748.      btst      #IOB_QUICK,d1               ; need to reply?
  749.      bne.b      10$                      ; nope, branch
  750.      pea      10$(pc)
  751.      jmp      _LVOReplyMsg(a6)              ; send it back
  752.      ;
  753.      ;      Abort all active/queued commands and reset internal state
  754.      ;
  755.      cnop 0,8 ; align for 040+
  756. cmd_Reset:
  757.      move.l   a1,-(sp)                  ; save I/O request
  758.      bsr.b      cmd_Flush                  ; go abort queued requests
  759.      ;
  760.     IFNE DANGER
  761.      move.w   #$04000,_intena
  762.      addq.b   #1,IDNestCnt(a6)              ; disable interrupts
  763.     ELSE
  764.      jsr      _LVODisable(a6)              ; disable interrupts
  765.     ENDC
  766.      ;
  767.      ;      This must follow the DISABLE
  768.      ;
  769.      exg      a5,a6                   ; exchange base and ExecBase
  770.      ;
  771.      move.l   cr_IOReq(pc),d0              ; active read?
  772.      beq.b      10$                      ; nope, branch
  773.      move.l   d0,a1                   ; get I/O request
  774.      bsr      dev_AbortIO                  ; go abort it
  775.      ;
  776.      ;
  777.      ;
  778. 10$     move.l   cw_IOReq(pc),d0              ; active write?
  779.      beq.b      20$                      ; nope, branch
  780.      move.l   d0,a1                   ; get I/O request
  781.      bsr      dev_AbortIO                  ; go abort it
  782.      ;
  783. 20$     exg      a5,a6                   ; restore base and ExecBase
  784.      move.l   (sp)+,a1                  ; restore I/O request
  785.      move.b   #8,IO_READLEN(a1)              ; set read length
  786.      move.b   #8,IO_WRITELEN(a1)              ; set write length
  787.      move.b   #1,IO_STOPBITS(a1)              ; set stop bits
  788.      move.l   vb_DefBaud(a5),IO_BAUD(a1)          ; set to default baud
  789.      move.l   vb_DefRBufLen(a5),IO_RBUFLEN(a1)    ; set to default buflen
  790.      bsr      internalReset               ; go set/verify parameters
  791.      move.b   d0,IO_ERROR(a1)              ; set error code
  792.      ;
  793.      ;      Set RC
  794.      ;
  795.      moveq      #0,d0                   ; I/O complete
  796.     IFNE DANGER
  797.      subq.b   #1,IDNestCnt(a6)
  798.      bge.b      enable$
  799.      move.w   #$C000,_intena              ; enable interrupts
  800. enable$  move.l   (sp)+,a0                  ; return
  801.      jmp      (a0)
  802.     ELSE
  803.      jmp      _LVOEnable(a6)              ; enable interrupts
  804.                               ; return
  805.     ENDC
  806.      ;
  807.      ;      Abort all "queued" requests, leaving all active alone.
  808.      ;
  809.      cnop 0,8 ; align for 040+
  810. cmd_Flush:
  811.      move.l   a2,-(sp)                  ; save registers
  812.      move.l   a1,-(sp)                  ; save registers
  813.      ;
  814.      ;      Abort all queued read requests.
  815.      ;
  816.      lea      readQ(pc),a2                  ; get ptr to read queue
  817.      bsr.b      20$                      ; branch to abort
  818.      ;
  819.      ;      Abort all queued write requests.
  820.      ;
  821.      lea      writeQ(pc),a2               ; get ptr to write queue
  822.      bsr.b      20$                      ; branch to abort
  823.      ;
  824.      ;      restore, and return to caller
  825.      ;
  826.      move.l   (sp)+,a1                  ; restore registers
  827.      move.l   (sp)+,a2                  ; restore registers
  828.      ;
  829.      ;      Set RC and return
  830.      ;
  831.      moveq      #0,d0                   ; I/O complete
  832.      ;
  833.      ;      !!!NOTE!!!  In a mad attempt to save 2 bytes, this RTS is used
  834.      ;      by the subroutine below.  Why waste 'em?  B-)
  835.      ;
  836. 10$     move.l   (sp)+,a0
  837.      jmp      (a0)                      ; return ( used below too!! )
  838.      ;
  839.      ;      Subroutine to remove and reply each I/O request.
  840.      ;
  841.      cnop 0,8 ; align for 040+
  842.     IFNE DANGER
  843. 20$     move.l   #custom+intena,a0
  844.      move.w   #$04000,(a0)
  845.      addq.b   #1,IDNestCnt(a6)              ; disable interrupts
  846.     ELSE
  847. 20$     jsr      _LVODisable(a6)              ; disable interrupts
  848.     ENDC
  849.      move.l   a2,8(a2)                  ; clear list
  850.      move.l   (a2)+,a1                  ; and get ptr to first I/O request
  851.      move.l   a2,-(a2)                  ;
  852.      move.l   a1,a2                   ; save I/O request in a2
  853.      ;
  854.     IFNE DANGER
  855.      subq.b   #1,IDNestCnt(a6)
  856.      bge.b      enable$
  857.      move.w   #$C000,(a0)                  ; enable interrupts
  858. enable$
  859.     ELSE
  860.      jsr      _LVOEnable(a6)              ; enable interrupts
  861.     ENDC
  862.      ;
  863. 25$     move.l   (a2),d0                  ; get next I/O request
  864.      beq.b      10$                      ; end of list? yep, branch to return
  865.      ;
  866.      pea      25$(pc)                  ; push return address
  867.      move.l   a2,a1                   ; move I/O request to a1
  868.      move.l   d0,a2                   ; save next I/O request in a2
  869.      andi.b   #~(1<<IOSERB_QUEUED),IO_FLAGS(a1)   ; no longer queued
  870.      move.b   #IOERR_ABORTED,IO_ERROR(a1)          ; store status
  871.      ;
  872.      jmp      _LVOReplyMsg(a6)              ; send it back / continue with next
  873.      ;
  874.      ;      Process a CMD_READ request.
  875.      ;
  876.      cnop 0,8 ; align for 040+
  877. cmd_Read:
  878.      ;
  879.      ;      Zero length requests just get returned.
  880.      ;
  881.      clr.l      IO_ACTUAL(a1)               ; clear bytes read
  882.      move.l   IO_LENGTH(a1),d0              ; get length and test
  883.      beq.b      20$                      ; yep, leave
  884.      ;
  885.      ;      This can be used to circumvent a bug in NComm 3.0 which
  886.      ;      references the buffer even when there was nothing read.
  887.      ;
  888.     IFNE     NCOMM
  889.      move.l   IO_DATA(A1),a0              ; get data pointer
  890.      clr.b      (a0)                      ; clear first byte in buffer
  891.     ENDC
  892.      ;
  893.      ;      The disable counter works just like exec's TDNestCnt field.  It's
  894.      ;      initialized to -1.  After incrementing, if it is 0, then we
  895.      ;      can attempt to process this request immediately.  If it's > 0,
  896.      ;      then we're already disabled and we must queue this request.
  897.      ;
  898.      addq.l   #1,disableRead              ; incr disable count
  899.      bgt.b      50$                      ; >0, already disabled
  900.      ;
  901.      ;      If we're already processing an request, this one has to wait
  902.      ;      until that one is done, so go queue it.
  903.      ;
  904.      tst.l      cr_IOReq(pc)                  ; have an active request?
  905.      bne.b      50$                      ; yep, go queue this one
  906.      ;
  907.      ;      If we don't have enough bytes to satisfy this request then go
  908.      ;      queue it.
  909.      ;
  910.      cmp.l      i_InCnt(pc),d0              ; length > current bytes?
  911.      bgt.b      50$                      ; yep, go queue it
  912.      ;
  913.      ;      Setup fields and go copy the data
  914.      ;
  915.     IFNE NCOMM
  916.      move.l   a0,cr_OutPtr                  ; get/set output ptr
  917.     ELSE
  918.      move.l   IO_DATA(a1),cr_OutPtr           ; get/set output ptr
  919.     ENDC
  920.      move.l   d0,cr_Length                  ; get/set output count
  921.      bsr      copyData                  ; go copy 'em
  922.      moveq      #0,d0                   ; I/O complete
  923.      ;
  924.      ;      We're done, so back off the disable counter.
  925.      ;
  926. 10$     subq.l   #1,disableRead              ; decr disable count
  927.      ;
  928.      ;      Return to caller
  929.      ;
  930. 20$     move.l   (sp)+,a0
  931.      jmp      (a0)                      ; return
  932.      ;
  933.      ;      Just set flags and queue.  The read interrupt will handle it.
  934.      ;
  935.      cnop 0,8 ; align for 040+
  936. 50$     ori.b      #1<<IOSERB_QUEUED,IO_FLAGS(a1)      ; indicate queued
  937.      ;
  938.      ;      Add this request to the end.
  939.      ;
  940.     IFNE DANGER
  941.      move.w   #$04000,_intena
  942.      addq.b   #1,IDNestCnt(a6)              ; disable interrupts
  943.     ELSE
  944.      jsr      _LVODisable(a6)              ; disable interrupts
  945.     ENDC
  946.      lea      readQ(pc),a0                  ; get pointer to read queue
  947.      ; This is the ADDTAIL macro
  948.      addq.l   #LH_TAIL,a0
  949.      move.l   LN_PRED(a0),d0
  950.      move.l   a1,LN_PRED(a0)
  951.      move.l   a0,(a1)
  952.      move.l   d0,4(a1)
  953.      move.l   d0,a0
  954.      move.l   a1,(a0)
  955.      ;
  956.      ;      Indicate that this request was not handled immediatly.
  957.      ;
  958.      moveq      #1,d0                   ; I/O not complete
  959.      ;
  960.     IFNE DANGER
  961.      subq.b   #1,IDNestCnt(a6)
  962.      bge.b      10$
  963.      move.w   #$C000,_intena              ; enable interrupts
  964.      bra.b      10$                      ; branch to return
  965.     ELSE
  966.      pea      10$(pc)                  ; branch to return
  967.      jmp      _LVOEnable(a6)              ; enable interrupts
  968.     ENDC
  969.      ;
  970.      ;      Process a CMD_WRITE request.
  971.      ;
  972.      cnop 0,8 ; align for 040
  973. cmd_Write:
  974.      clr.l      IO_ACTUAL(a1)               ; clear bytes written
  975.      move.l   IO_LENGTH(a1),d0              ; get length
  976.      bne.b      10$                      ; yep, proccess
  977. 5$     move.l   (sp)+,a0
  978.      jmp      (a0)                      ; return
  979.      cnop 0,8 ; align for 040
  980. 10$
  981.     IFNE EOFCODE
  982.      btst      #SERB_EOFMODE,IO_SERFLAGS(a1)       ; EOFMODE requested?
  983.      beq.b      20$                      ; nope, branch
  984.      move.b   #SerErr_InvParam,IO_ERROR(a1)       ; Set error
  985.      moveq      #0,d0                   ; I/O Complete
  986.      bra.b      5$
  987.      cnop 0,8 ; align for 040
  988. 20$
  989.     ENDC
  990.     IFNE NEGCHECK
  991.      ;
  992.      ; Check for -1 length
  993.      ;
  994.      cmp.l      #-1,d0                  ; length = -1?
  995.      bne.b      sdcmd_Break                  ; nope, skip scan
  996.      ;
  997.      ;      Scan the data for null to calc the length
  998.      ;
  999.      move.l   a0,d1                   ; save data ptr
  1000. 30$     tst.b      (a0)+                   ; does it equal 0? (first byte)
  1001.      beq.b      40$                      ; yep, finish
  1002.      tst.b      (a0)+                   ; does it equal 0? (second byte)
  1003.      beq.b      40$                      ; yep, finish
  1004.      tst.b      (a0)+                   ; does it equal 0? (third byte)
  1005.      beq.b      40$                      ; yep, finish
  1006.      tst.b      (a0)+                   ; does it equal 0? (fourth byte)
  1007.      bne.b      30$                      ; nope, loop
  1008. 40$     move.l   a0,d0
  1009.      sub.l      d1,d0                   ; calc # of bytes
  1010.      move.l   d0,IO_LENGTH(a1)              ; save length
  1011.      bra.b      sdcmd_Break
  1012.      nop                          ; fix possable compiler bug
  1013.     ENDC
  1014.      ;
  1015.      ;      Entry point for Break command and fall through from cmd_Write.
  1016.      ;
  1017.      cnop 0,8 ; align for 040
  1018. sdcmd_Break:
  1019.      ;
  1020.      ;      Just set flags and queue. The TBE interrupt will handle it.
  1021.      ;
  1022.      ori.b      #1<<IOSERB_QUEUED,IO_FLAGS(a1)      ; indicate queued
  1023.      ;
  1024.      ;      Protect.
  1025.      ;
  1026.     IFNE DANGER
  1027.      move.w   #$04000,_intena
  1028.      addq.b   #1,IDNestCnt(a6)              ; disable interrupts
  1029.     ELSE
  1030.      jsr      _LVODisable(a6)              ; disable interrupts
  1031.     ENDC
  1032.      ;
  1033.      ;      Add request to end of queue.
  1034.      ;
  1035.      lea      writeQ(pc),a0               ; get queue list ptr
  1036.      ; This is the ADDTAIL macro
  1037.      addq.l   #LH_TAIL,a0
  1038.      move.l   LN_PRED(a0),d0
  1039.      move.l   a1,LN_PRED(a0)
  1040.      move.l   a0,(a1)
  1041.      move.l   d0,4(a1)
  1042.      move.l   d0,a0
  1043.      move.l   a1,(a0)
  1044.      ;
  1045.      ;      If we have an active request, don't force interrupt.
  1046.      ;
  1047.      tst.l      cw_IOReq(pc)                  ; have an active request?
  1048.      bne.b      10$                      ; yep, branch
  1049.      ;
  1050.      ;      Force a TBE interrupt to get the writes going.
  1051.      ;
  1052.      move.w   #INTF_SETCLR|INTF_TBE,_intreq       ; make TBE pending
  1053.      ;
  1054.      ;      Enable, set RC and return to caller.
  1055.      ;
  1056. 10$     moveq      #1,d0                   ; I/O not complete
  1057.     IFNE DANGER
  1058.      subq.b   #1,IDNestCnt(a6)
  1059.      bge.b      enable$
  1060.      move.w   #$C000,_intena              ; enable interrupts
  1061. enable$  move.l   (sp)+,a0                  ; return
  1062.      jmp      (a0)
  1063.     ELSE
  1064.      jmp      _LVOEnable(a6)              ; enable interrupts
  1065.                               ; return
  1066.     ENDC
  1067.      ;
  1068.      ;      Resets serial read buffer
  1069.      ;
  1070.      ;      Since this routine is called internally, it must NOT reference
  1071.      ;      the I/O request.
  1072.      ;
  1073.      cnop 0,8 ; align for 040+
  1074. cmd_Clear:
  1075.     IFNE DANGER
  1076.      move.w   #$04000,_intena
  1077.      addq.b   #1,IDNestCnt(a6)              ; disable interrupts
  1078.     ELSE
  1079.      jsr      _LVODisable(a6)              ; disable interrupts
  1080.     ENDC
  1081.      ;
  1082.      ;      Load registers
  1083.      ;
  1084.      move.l   vb_CurRBuf(a5),d0              ; get internal buffer ptr
  1085.      move.l   vb_CurRBufLen(a5),d1              ; and internal buffer len
  1086.      lea      i_BufPtr(pc),a0              ; get ptr internal control
  1087.      ;
  1088.      ;      Initialize global buffer variables
  1089.      ;
  1090.      move.l   d0,(a0)+                  ; store buffer ptr
  1091.      move.l   d0,(a0)+                  ; set current input ptr
  1092.      move.l   d0,(a0)+                  ; set current output ptr
  1093.      add.l      d1,d0                   ; add buffer length
  1094.      move.l   d0,(a0)+                  ; store ptr to end of buffer
  1095.      clr.l      (a0)+                   ; clear byte cnt
  1096.      move.l   vb_CurBaud(a5),d0              ; get internal baud
  1097.      lsr.l      #4,d0                   ; divide by 16
  1098.      sub.l      d0,d1                   ; subtract from length
  1099.      move.l   d1,(a0)                  ; set threshold
  1100.      ;
  1101.      ;      Enable, set RC and return.
  1102.      ;
  1103.      moveq      #0,d0                   ; I/O complete
  1104.     IFNE DANGER
  1105.      subq.b   #1,IDNestCnt(a6)
  1106.      bge.b      enable$
  1107.      move.w   #$C000,_intena              ; enable interrupts
  1108. enable$  move.l   (sp)+,a0                  ; return
  1109.      jmp      (a0)
  1110.     ELSE
  1111.      jmp      _LVOEnable(a6)              ; enable interrupts
  1112.     ENDC
  1113.      ;
  1114.      ;
  1115.      ;
  1116.      cnop 0,8 ; align for 040+
  1117. cmd_Invalid
  1118.      move.b   #IOERR_NOCMD,IO_ERROR(a1)          ; set bad status
  1119.      move.l   (sp)+,a0
  1120.      moveq      #0,d0                   ; I/O complete
  1121.      jmp      (a0)                      ; return
  1122.      ;
  1123.      ;      Returns number of bytes currently in internal buffer and
  1124.      ;      current serial port status.
  1125.      ;
  1126.      ;      NOTE:  Not completely compatible with standard serial.device
  1127.      ;      since it doesn't return the upper byte of IO_STATUS.
  1128.      ;
  1129.      cnop 0,8 ; align for 040+
  1130. sdcmd_Query:
  1131.     IFNE DANGER
  1132.      move.l   #custom+intena,a0
  1133.      move.w   #$04000,(a0)
  1134.      addq.b   #1,IDNestCnt(a6)              ; disable interrupts
  1135.     ELSE
  1136.      jsr      _LVODisable(a6)              ; disable interrupts
  1137.     ENDC
  1138.      moveq      #0,d0                   ; clear d0
  1139.      move.b   _ciabpra,d0                  ; get PR register
  1140.      andi.w   #~PRTMASK,d0                  ; zap printer bits
  1141.      ;
  1142.      ;      To use this Set SETDSR to one.  This was done
  1143.      ;      for a user whose DSR pin did not function.
  1144.      ;
  1145.     IFNE SETDSR
  1146.      andi        #~(1<<CIAB_COMDSR),d0              ; set DSR
  1147.     ENDC
  1148.      ;
  1149.      ;
  1150.      ;
  1151.      move.w   d0,IO_STATUS(a1)              ; store status
  1152.      move.l   i_InCnt(pc),IO_ACTUAL(a1)          ; byte left in buffer
  1153.      ;
  1154.      ;      Enable, set RC and return.
  1155.      ;
  1156.      moveq      #0,d0                   ; I/O complete
  1157.     IFNE DANGER
  1158.      subq.b   #1,IDNestCnt(a6)
  1159.      bge.b      enable$
  1160.      move.w   #$C000,(a0)                  ; enable interrupts
  1161. enable$  move.l   (sp)+,a0                  ; return
  1162.      jmp      (a0)
  1163.     ELSE
  1164.      jmp      _LVOEnable(a6)              ; enable interrupts
  1165.                               ; return
  1166.     ENDC
  1167.      ;
  1168.      ;
  1169.      ;
  1170.      cnop 0,8 ; align for 040+
  1171. sdcmd_SetParams:
  1172.      ;
  1173.      ;      Validate the read, write, and stop bit lengths.
  1174.      ;
  1175.      cmp.b      #8,IO_READLEN(a1)              ; 8 bit chars for read?
  1176.      bne.b      40$                      ; nope, branch
  1177.      cmp.b      #8,IO_WRITELEN(a1)              ; 8 bit chars for write?
  1178.      bne.b      40$                      ; nope, branch
  1179.      cmp.b      #1,IO_STOPBITS(a1)              ; 1 stop bit?
  1180.      bne.b      40$                      ; nope, branch
  1181.      ;
  1182.      ;      Get and validate the baud rate.
  1183.      ;
  1184.      move.l   IO_BAUD(a1),d1              ; get baud from I/O req
  1185.      bne.b      20$                      ; specified?
  1186.      move.l   vb_CurBaud(a5),d1              ; get current baud from base
  1187.      bne.b      20$                      ; specified?
  1188.      move.l   vb_DefBaud(a5),d1              ; get default baud from base
  1189. 20$     cmp.l      #110,d1                  ; too low?
  1190.      blt.b      40$                      ; error
  1191.      cmp.l      #292000,d1                  ; too high?
  1192.      bgt.b      40$                      ; error
  1193.      ;
  1194.      ;      Get and validate the buffer length.
  1195.      ;
  1196.      move.l   IO_RBUFLEN(a1),d0              ; get buffer length
  1197.      bne.b      30$                      ; specified?
  1198.      move.l   vb_CurRBufLen(a5),d0              ; get current from base
  1199.      bne.b      30$                      ; specified?
  1200.      move.l   vb_DefRBufLen(a5),d0              ; get default from base
  1201.      ;
  1202. 30$     bsr.b      internalReset               ; go init baud and buffer
  1203. 35$     move.b   d0,IO_ERROR(a1)              ; set error code
  1204.      bne.b      39$
  1205.      ;
  1206.      ;      If the 7wire bit is not on, we will only use 3-wire protocol
  1207.      ;
  1208.      moveq      #0,d0                   ; clear flag
  1209.      btst      #SERB_7WIRE,IO_SERFLAGS(a1)          ; use 7wire handshaking?
  1210.      beq.b      36$                      ; nope, branch
  1211.      moveq      #1,d0                   ; set flag
  1212. 36$     move.l   d0,Handshake                  ; store flag
  1213.      ;
  1214.      ;      Set RC and return.
  1215.      ;
  1216. 39$
  1217.      move.l   (sp)+,a0
  1218.      moveq      #0,d0                   ; I/O complete
  1219.      jmp      (a0)                      ; return
  1220.      ;
  1221.      ;      Invalid parm detected.
  1222.      ;
  1223.      cnop 0,8 ; align for 040+
  1224. 40$     moveq      #SerErr_InvParam,d0              ; set error
  1225.      bra.b      35$                      ; go return
  1226.      ;
  1227.      cnop 0,8 ; align for 040+
  1228. nscmd_DeviceQuery:
  1229.      move.l   IO_DATA(a1),d0
  1230.      beq.b      10$
  1231.      move.l   d0,a0
  1232.      move.l   #NSDEVICEQUERYRESULT_SIZE,SIZEAVAILABLE(a0)
  1233.      move.l   #NSDEVICEQUERYRESULT_SIZE,IO_ACTUAL(a1)
  1234.      move.w   #NSDEVTYPE_SERIAL,DEVICETYPE(a0)
  1235.      move.l   a1,-(sp)
  1236.      lea      cmdlist(pc),a1
  1237.      move.l   a1,SUPPORTEDCOMMANDS(a0)
  1238.      move.l   (sp)+,a1
  1239. 10$
  1240.      move.l   (sp)+,a0
  1241.      moveq      #0,d0
  1242.      jmp      (a0)
  1243.      ;
  1244.      ;      Reset the buffer and baud rate
  1245.      ;
  1246.      ;      Registers:  D0 = Buffer length
  1247.      ;              D1 = Baud rate
  1248.      ;
  1249.      cnop 0,8 ; align for 040+
  1250. internalReset:
  1251.      ;
  1252.      ;      Disable interrupts.
  1253.      ;
  1254.     IFNE DANGER
  1255.      move.w   #$04000,_intena
  1256.      addq.b   #1,IDNestCnt(a6)              ; disable interrupts
  1257.     ELSE
  1258.      jsr      _LVODisable(a6)              ; disable interrupts
  1259.     ENDC
  1260.      ;
  1261.      ;      Save buffer length and go set serper.
  1262.      ;
  1263.      move.l   d0,-(sp)                  ; save D0
  1264.      move.l   d1,d0                   ; get baud rate
  1265.      ;
  1266.      ;      Set serial period register
  1267.      ;
  1268.      cmp.l      vb_CurBaud(a5),d0              ; current baud = new baud?
  1269.      beq.b      40$                      ; yep, just exit
  1270.      move.l   d0,vb_CurBaud(a5)              ; save new baud
  1271.      move.l   d0,d1                   ; save again
  1272.      lsl.l      #3,d0                   ; baud *= 8
  1273.      sub.l      d1,d0                   ; baud -= saved baud
  1274.      move.l   #25000000,d1                  ; get NTSC base
  1275.      cmpi.b   #50,PowerSupplyFrequency(a6)          ; PAL machine?
  1276.      bne.b      5$                      ; nope, branch
  1277.      move.l   #24772416,d1                  ; get PAL base
  1278. 5$     cmp.l      #$FFFF,d0                  ; Divide
  1279.      ble.b      20$                      ;
  1280.      lsr.l      #5,d0                   ;
  1281.     IFNE NEWCODE
  1282.      divu.l   d0,d1                   ;
  1283.     ELSE
  1284.      divu.w   d0,d1                   ;
  1285.      andi.l   #$FFFF,d1                  ;
  1286.     ENDC
  1287.      lsr.l      #5,d1                   ;
  1288.      bra.b      30$                      ;
  1289.      cnop 0,8 ; align for 040+
  1290. 20$     divu.w   d0,d1                   ;
  1291. 30$     move.w   d1,_serper                  ; set period value
  1292. 40$
  1293.      move.l   (sp)+,d0                  ; restore D0
  1294.      ;
  1295.      ;      Determine if the buffer length is adequate for the selected CPS.
  1296.      ;      If not, use 64K for the length.
  1297.      ;
  1298.      move.l   vb_CurBaud(a5),d1              ; get current baud
  1299.      lsr.l      #2,d1                   ; divide by 4
  1300.      cmp.l      d1,d0                   ; buflen > CPS
  1301.      bhi.b      10$                      ; yep, branch
  1302.      move.l   #65536,d0                  ; else use 64K
  1303.      ;
  1304.      ;      Allocate new internal buffer
  1305.      ;
  1306. 10$     cmp.l      vb_CurRBufLen(a5),d0              ; len same as previous?
  1307.      beq.b      6$                      ; yep, so no need to alloc
  1308.      move.l   d0,d1                   ; save length
  1309.      move.l   a1,-(sp)                  ; save registers
  1310.      move.l   d1,-(sp)                  ; save registers
  1311.      moveq      #MEMF_PUBLIC|MEMF_FAST,d1          ; public fast memory
  1312.      jsr      _LVOAllocMem(a6)              ; go allocate it
  1313.      move.l   (sp)+,d1                  ; restore registers
  1314.      move.l   (sp)+,a1                  ; restore registers
  1315.      tst.l      d0                      ; did we get it?
  1316.      beq.b      21$                      ; if zero, error
  1317.      move.l   d0,-(sp)                  ; save d0
  1318.      bsr.b      freeBuf                  ; go free previous buffer
  1319.      move.l   (sp)+,vb_CurRBuf(a5)              ; store new ptr
  1320.      move.l   d1,vb_CurRBufLen(a5)              ; and length
  1321.      bsr      cmd_Clear                  ; go setup buffer
  1322. 6$     moveq      #0,d0                   ; success
  1323.      bra.b      22$                      ; return
  1324.      cnop 0,8 ; align for 040+
  1325. 21$     moveq      #SerErr_BufErr,d0              ; set error status
  1326. 22$
  1327.      ;
  1328.      ;      Enable and return to caller.
  1329.      ;
  1330.     IFNE DANGER
  1331.      subq.b   #1,IDNestCnt(a6)
  1332.      bge.b      enable$
  1333.      move.w   #$C000,_intena              ; enable interrupts
  1334. enable$  move.l   (sp)+,a0                  ; return
  1335.      jmp      (a0)
  1336.     ELSE
  1337.      jmp      _LVOEnable(a6)              ; enable interrupts
  1338.     ENDC
  1339.      ;
  1340.      ;      Free internal buffer
  1341.      ;
  1342.      cnop 0,8 ; align for 040+
  1343. freeBuf:
  1344.      move.l   vb_CurRBuf(a5),d0              ; is one there?
  1345.      beq.b      10$                      ; no so branch
  1346.      move.l   a1,-(sp)                  ; save registers
  1347.      move.l   d1,-(sp)                  ; save registers
  1348.      move.l   d0,a1                   ; get ptr
  1349.      move.l   vb_CurRBufLen(a5),d0              ; get length
  1350.      clr.l      vb_CurRBuf(a5)              ; clear
  1351.      clr.l      vb_CurRBufLen(a5)              ; clear
  1352.      jsr      _LVOFreeMem(a6)              ; free it
  1353.      move.l   (sp)+,d1                  ; restore registers
  1354.      move.l   (sp)+,a1                  ; restore registers
  1355. 10$     move.l   (sp)+,a0                  ; return
  1356.      jmp      (a0)
  1357.      ;
  1358.      ;      Checks CTS status and if clear generates a TBE interrupt or
  1359.      ;      requeues the timer request.
  1360.      ;
  1361.      ;      Entered from Exec using the MsgPort callback.
  1362.      ;
  1363.      ;      Input:   a6 = ExecBase
  1364.      ;      Output:  none
  1365.      ;
  1366.      ;      No need to preserve d0/d1/a0/a1
  1367.      ;
  1368.      cnop 0,8 ; align for 040+
  1369. timerRtn:
  1370.      lea      timerReq(pc),a1              ; get ptr to timer request
  1371.      ; This is the REMOVE macro
  1372.      move.l   (a1)+,a0
  1373.      move.l   (a1),a1
  1374.      move.l   a0,(a1)
  1375.      move.l   a1,LN_PRED(a0)
  1376.      ;
  1377.      ;      If we were breaking, reset adkcon.
  1378.      ;
  1379.      move.l   #custom+adkconr,a0              ; get ptr to custom regs
  1380.      btst      #ADKB_UARTBRK&7,(a0)              ; were we breaking?
  1381.      beq.b      10$                      ; nope, skip reset
  1382.      ;
  1383.      move.w   #ADKF_UARTBRK,adkcon-adkconr(a0)    ; stop breaking
  1384.      ;
  1385.      ;
  1386.      ;
  1387. 10$     tst.l      Handshake(pc)               ; are we handshaking?
  1388.      beq.b      20$                      ; nope, generate interrupt
  1389.      btst      #CIAB_COMCTS,_ciabpra           ; clear to send?
  1390.      beq.b      20$                      ; yep, go start writing
  1391.      ;
  1392.      lea      timerReq(pc),a1              ; get ptr to timer request
  1393.      move.l   #1000,IOTV_TIME+TV_MICRO(a1)          ; wait for .001 seconds
  1394.      jmp      _LVOSendIO(a6)              ; go queue it / return
  1395.      ;
  1396.      ;      CTS is clear so generate TBE interrupt to restart writing
  1397.      ;
  1398.      cnop 0,8 ; align for 040+
  1399. 20$     move.w   #INTF_SETCLR|INTF_TBE,intreq-adkconr(a0)  ; set TBE interrupt
  1400. 30$     move.l   (sp)+,a0
  1401.      jmp      (a0)                      ; return
  1402.      ;
  1403.      ;    Non serial interrupt
  1404.      ;    Handles:
  1405.      ;        INTB_DSKBLK
  1406.      ;        INTB_SOFTINT
  1407.      ;
  1408.      ;  a0 - custom chips base
  1409.      ;  a1 - is_Data
  1410.      ;
  1411.      cnop 0,8 ; align for 040+
  1412. level1n:
  1413.      move.l   a6,-(sp)                  ; save registers
  1414.      move.l   a5,-(sp)                  ; save registers
  1415.      move.l   a1,-(sp)                  ; save registers
  1416.      move.l   d1,-(sp)                  ; save registers
  1417.      move.l   d0,d1                   ; get enabled interrupts
  1418.      swap      d1
  1419.      move.l   SysBase(pc),a6              ; get ExecBase
  1420.      and.l      d0,d1                   ; and in requested interrupts
  1421.      ;
  1422.      btst      #INTB_DSKBLK,d1              ; Disk block done?
  1423.      beq.b      10$                      ; nope, branch
  1424.      ;
  1425.      move.l   IVDSKBLK(a6),a1              ; get data and code ptrs
  1426.      move.l   IVDSKBLK+4(a6),a5              ; get data and code ptrs
  1427.      pea      20$(pc)                  ; push return address
  1428.      jmp      (a5)                      ; jump to routine
  1429.      ;
  1430.      cnop 0,8 ; align for 040+
  1431.      ;
  1432. 10$     move.l   IVSOFTINT(a6),a1              ; get data and code ptrs
  1433.      move.l   IVSOFTINT+4(a6),a5              ; get data and code ptrs
  1434.      jsr      (a5)                      ; jump to routine
  1435.      ;
  1436. 20$
  1437.      move.l   (sp)+,d1                  ; restore registers
  1438.      move.l   (sp)+,a1                  ; restore registers
  1439.      move.l   (sp)+,a5                  ; restore registers
  1440.      move.l   (sp)+,a6                  ; restore registers
  1441.      move.l   (sp)+,a0                  ; restore registers
  1442.      move.l   (sp)+,d0                  ; restore registers
  1443.      rte                          ; return
  1444.      ;
  1445.      ;    Level 1 interrupt handler
  1446.      ;    Handles:
  1447.      ;        INTB_TBE
  1448.      ;
  1449.      ;  a1 - is_Data
  1450.      ;
  1451.      cnop 0,8 ; align for 040+
  1452. level1:
  1453.      move.l   d0,-(sp)                  ; save D0 (faster than MOVEM)
  1454.      move.l   a0,-(sp)                  ; save A0 (faster than MOVEM)
  1455.      move.l   #custom,a0                  ; get ptr to custom regs
  1456.      move.l   intenar(a0),d0              ; get intenar & intreqr
  1457.      btst      #INTB_INTEN+16,d0              ; interrupts enabled?
  1458.      beq.b      30$                      ; nope, ignore
  1459.      btst      #INTB_TBE,d0                  ; xmit buffer empty?
  1460.      beq.b      level1n                  ; nope, invoke old handler
  1461.      ;
  1462.      ;      Handle "Transmit Buffer Empty" interrupt (write)
  1463.      ;
  1464.      move.w   #INTF_TBE,intreq(a0)              ; clear interrupt
  1465.      ;
  1466.      ;      If we're not handshaking, bypass it.
  1467.      ;
  1468. 10$     tst.l      Handshake(pc)               ; are we handshaking?
  1469.      beq.b      20$                      ; nope, skip CTS test
  1470.      btst      #CIAB_COMCTS,_ciabpra           ; clear to send?
  1471.      bne.b      40$                      ; nope, branch
  1472.      ;
  1473.      ;      If cw_Length goes negative here, we are either done with a
  1474.      ;      request or we were called as a result of a fake interrupt
  1475.      ;      to force us to get the next request going.
  1476.      ;
  1477. 20$     subq.l   #1,cw_Length                  ; decr write length
  1478.      blt.b      60$                      ; < zero, done, branch
  1479.      ;
  1480.      ;      Currently processing a request.
  1481.      ;
  1482.      move.l   cw_Buffer(pc),a0              ; get buffer ptr
  1483.      move.w   #256,d0                  ; set stop bit
  1484.      move.b   (a0)+,d0                  ; get next byte
  1485.      move.l   a0,cw_Buffer                  ; store buffer ptr
  1486.      move.w   d0,_serdat                  ; store in serdat reg
  1487.      ;
  1488. 30$     move.l   (sp)+,a0                  ; restore registers
  1489.      move.l   (sp)+,d0                  ; restore registers
  1490.      rte                          ; return
  1491.      ;
  1492.      ;      Queue a timer request to recheck CTS status
  1493.      ;
  1494. 40$     move.l   a6,-(sp)                  ; save registers
  1495.      move.l   d1,-(sp)                  ; save registers
  1496.      move.l   a1,-(sp)                  ; save registers
  1497.      lea      timerReq(pc),a1              ; get ptr to timer request
  1498.      move.l   #1000,IOTV_TIME+TV_MICRO(a1)          ; wait for .001 seconds
  1499.      move.l   SysBase(pc),a6              ; get ExecBase
  1500.      jsr      _LVOSendIO(a6)              ; queue the request
  1501.      move.l   (sp)+,a1                  ; restore registers
  1502.      move.l   (sp)+,d1                  ; restore registers
  1503.      move.l   (sp)+,a6                  ; restore registers
  1504.      bra.b      30$                      ; go return
  1505.      ;
  1506.      ;      There aren't anymore requests, so clear and exit
  1507.      ;
  1508.      cnop 0,8 ; align for 040+
  1509. 50$     clr.l      cw_Length-Start(a6)              ; clear length
  1510.      clr.l      cw_IOReq-Start(a6)              ; clear
  1511.      move.l   (sp)+,d1                  ; restore registers
  1512.      move.l   (sp)+,a1                  ; restore registers
  1513.      move.l   (sp)+,a6                  ; restore registers
  1514.      bra.b      30$                      ; go return
  1515.      ;
  1516.      ;      Write request completed
  1517.      ;
  1518.      cnop 0,8 ; align for 040+
  1519. 60$     move.l   a6,-(sp)                  ; save registers
  1520.      move.l   a1,-(sp)                  ; save registers
  1521.      move.l   d1,-(sp)                  ; save registers
  1522.      ;
  1523.      move.l   cw_IOReq(pc),d0              ; active I/O request?
  1524.      beq.b      70$                      ; nope, branch
  1525.      ;
  1526.      ;      Reply it and setup for next
  1527.      ;
  1528.      move.l   d0,a1                   ; get I/O request
  1529.      andi.b   #~(1<<IOSERB_ACTIVE),IO_FLAGS(a1)   ; no longer active
  1530.      clr.b      IO_ERROR(a1)                  ; no error
  1531.      move.l   SysBase(pc),a6              ; get ExecBase
  1532.      jsr      _LVOReplyMsg(a6)              ; return I/O request
  1533.      ;
  1534. 70$     lea      Start(pc),a6                  ; get section base
  1535.      ;
  1536.      lea      writeQ(pc),a1               ; get ptr to write queue
  1537.      move.l   (a1),a0                  ; get head of list
  1538.      move.l   (a0),d0                  ; get successor
  1539.      beq.b      50$                      ; end of list? yep, branch
  1540.      ;
  1541.      ;      Remove the node from the list
  1542.      ;
  1543.      move.l   d0,(a1)                  ; make new head
  1544.      exg.l      d0,a0                   ; swap nodes
  1545.      move.l   a1,LN_PRED(a0)              ; store predecessor
  1546.      ;
  1547.      move.l   d0,a1                   ; get I/O request
  1548.      ;
  1549.      ;      If it's a BREAK, then branch to process as such.
  1550.      ;
  1551.      cmpi.w   #SDCMD_BREAK,IO_COMMAND(a1)          ; BREAK command?
  1552.      beq.b      100$                      ; yep, branch
  1553.      ;
  1554.      ;      Check for absolute length
  1555.      ;
  1556.      move.l   IO_DATA(a1),a0              ; get data ptr
  1557.      move.l   IO_LENGTH(a1),d0              ; get length
  1558.      move.l   d0,IO_ACTUAL(a1)              ; go ahead and set it
  1559.      move.b   IO_FLAGS(a1),d1
  1560.      move.l   d0,cw_Length-Start(a6)          ; store length
  1561.      andi.b   #~(1<<IOSERB_QUEUED),d1          ; no longer queued
  1562.      move.l   a0,cw_Buffer-Start(a6)          ; store buffer ptr
  1563.      ori.b      #1<<IOSERB_ACTIVE,d1              ; make it active
  1564.      move.l   a1,cw_IOReq-Start(a6)           ; store I/O request ptr
  1565.      move.b   d1,IO_FLAGS(a1)
  1566.      ;
  1567.      move.l   (sp)+,d1                  ; restore registers
  1568.      move.l   (sp)+,a1                  ; restore registers
  1569.      move.l   (sp)+,a6                  ; restore registers
  1570.      bra      10$                      ; go start request
  1571.      ;
  1572.      ;      Start the BREAK.
  1573.      ;
  1574.      cnop 0,8 ; align for 040+
  1575. 100$     move.b   IO_FLAGS(a1),d1
  1576.      clr.l      cw_Length-Start(a6)              ; clear length
  1577.      andi.b   #~(1<<IOSERB_QUEUED),d1          ; no longer queued
  1578.      move.l   a1,cw_IOReq-Start(a6)           ; store I/O request ptr
  1579.      ori.b      #1<<IOSERB_ACTIVE,d1              ; make it active
  1580.      move.w   #ADKF_SETCLR|ADKF_UARTBRK,_adkcon   ; start break
  1581.      move.b   d1,IO_FLAGS(a1)
  1582.      move.l   IO_BRKTIME(a1),d0              ; get break time
  1583.      lea      timerReq(pc),a1              ; get ptr to timer request
  1584.      move.l   d0,IOTV_TIME+TV_MICRO(a1)          ; set the timeout
  1585.      move.l   SysBase(pc),a6              ; get ExecBase
  1586.      jsr      _LVOSendIO(a6)              ; queue the request
  1587.      move.l   (sp)+,d1                  ; restore registers
  1588.      move.l   (sp)+,a1                  ; restore registers
  1589.      move.l   (sp)+,a6                  ; restore registers
  1590.      bra      30$                      ; go exit
  1591.      ;
  1592.      ;    Non serial interrupt
  1593.      ;    Handles:
  1594.      ;        INTB_DSKSYNC
  1595.      ;
  1596.      ;  a0 - custom chips base
  1597.      ;
  1598.      cnop 0,8 ; align for 040+
  1599. level5n:
  1600.      move.l   a6,-(sp)                  ; save registers
  1601.      move.l   a5,-(sp)                  ; save registers
  1602.      move.l   d1,-(sp)                  ; save registers
  1603.      move.l   a1,-(sp)                  ; save registers
  1604.      move.l   d0,d1
  1605.      move.l   SysBase(pc),a6              ; get ExecBase
  1606.      swap      d1
  1607.      move.l   IVDSKSYNC(A6),a1              ; get data and code ptrs
  1608.      and.l      d0,d1
  1609.      move.l   #custom,a0                  ; get ptr to custom regs
  1610.      move.l   IVDSKSYNC+4(A6),a5              ; get data and code ptrs
  1611.      jsr      (a5)                      ; branch to routine
  1612.      move.l   (sp)+,a1                  ; restore registers
  1613.      move.l   (sp)+,d1                  ; restore registers
  1614.      move.l   (sp)+,a5                  ; restore registers
  1615.      move.l   (sp)+,a6                  ; restore registers
  1616.      move.l   (sp)+,a0                  ; restore registers
  1617.      move.l   (sp)+,d0                  ; restore registers
  1618.      rte                          ; return
  1619.      ;
  1620.      ;    Default Level 5 handler
  1621.      ;    Handles:
  1622.      ;        INTB_RBF
  1623.      ;
  1624.      ;  a1 - custom chips base
  1625.      ;
  1626.      cnop 0,8 ; align for 040+
  1627. level5:
  1628.      move.l   d0,-(sp)                  ; save registers
  1629.      move.l   a0,-(sp)                  ; save registers
  1630.      move.l   #custom+serdatr,a0              ; get ptr to custom regs
  1631.      ;
  1632.      move.l   intenar-serdatr(a0),d0          ; get intenar & intreqr
  1633.      btst      #INTB_INTEN+16,d0              ; interrupts enabled?
  1634.      beq.b      41$                      ; nope, ignore
  1635.      btst      #INTB_RBF,d0                  ; receive buffer full?
  1636.      beq.b      level5n                  ; nope, invoke old handler
  1637.      ;
  1638. 10$     move.w   (a0),d0                  ; Overrun?
  1639.      bpl.b      20$                      ; nope, branch
  1640.      ;
  1641.      ;      We've missed some data, so set overrun flag.
  1642.      ;
  1643.      addq.l   #1,Overrun                  ; set overrun flag
  1644. 20$     move.w   #INTF_RBF,intreq-serdatr(a0)          ; clear RBF interrupt
  1645.      move.l   i_BufIn(pc),a0              ; get current ptr
  1646.      move.b   d0,(a0)+                  ; store received byte
  1647.      addq.l   #1,i_InCnt                  ; incr bytes in buffer
  1648.      ;
  1649.      cmpa.l   i_BufEnd(pc),a0              ; hit end of buffer?
  1650.      bne.b      30$                      ; nope, branch
  1651.      ;
  1652.      ;      Hit physical end of buffer, so wrap to the start of the buffer.
  1653.      ;
  1654.      move.l   i_BufPtr(pc),a0              ; get buffer ptr
  1655. 30$     move.l   a0,i_BufIn                  ; store input ptr
  1656.      ;
  1657.      subq.l   #1,i_Thresh                  ; close to full buffer?
  1658.      bne.b      40$                      ; nope, branch
  1659.      ;
  1660.      ;      Hit buffer threshold, so tell other end not to send any more
  1661.      ;      data.
  1662.      ;
  1663.      tst.l      Handshake(pc)               ; are we handshaking?
  1664.      beq.b      40$                      ; nope, skip RTS
  1665.      ori.b      #1<<CIAB_COMRTS,_ciabpra          ; block further input
  1666.      ;
  1667. 40$
  1668.     IFEQ NEWCODE
  1669.      move.l   #custom+serdatr,a0              ; get ptr to custom regs
  1670.      btst      #INTB_RBF&7,intreqr-serdatr(a0)     ; receive buffer full?
  1671.      bne.b      10$                      ; yep, go get another byte
  1672.     ENDC
  1673.      ;
  1674. 41$     move.l   (sp)+,a0                  ; restore registers
  1675.      move.l   (sp)+,d0                  ; restore registers
  1676.      rte                          ; return
  1677.      ;
  1678.      ;
  1679.      ;  a1 - IS_DATA
  1680.      ;  a5 - jump vector register
  1681.      ;
  1682.      cnop 0,8 ; align for 040+
  1683. level2:
  1684.      ;
  1685.      ;      If there's nothing in the buffer, there's no point in going
  1686.      ;      any further.
  1687.      ;
  1688.      tst.l      i_InCnt(pc)                  ; anything in the buffer?
  1689.      beq.b      9$                      ; nope, branch
  1690.      ;
  1691.      ;      If we've been "disabled" then get out.
  1692.      ;
  1693. 20$     tst.l      disableRead(pc)              ; internally disabled?
  1694.      bge.b      10$                      ; yep, get out of here
  1695.      lea      Start(pc),a5                  ; get base
  1696.      ;
  1697.      ;      If we have an active request, branch down and try to fulfill it.
  1698.      ;
  1699.      move.l   cr_IOReq(pc),d0              ; get and test active I/O
  1700.      bne.b      30$                      ; nzero, active, branch
  1701.      ;
  1702.      ;      Get first node in list and test if empty.
  1703.      ;
  1704.      move.l   (a1),a0                  ; get head of list
  1705.      move.l   (a0),d0                  ; get successor
  1706.      beq.b      9$                      ; end of list? yep, branch
  1707.      ;
  1708.      ;      Remove the node from the list
  1709.      ;
  1710.      move.l   d0,(a1)                  ; make new head
  1711.      exg.l      d0,a0                   ; swap nodes
  1712.      move.l   a1,LN_PRED(a0)              ; store predecessor
  1713.      ;
  1714.      ;      Setup fields for processing a read request
  1715.      ;
  1716.      move.l   d0,a1                   ; get I/O request
  1717.      move.b   IO_FLAGS(a1),d1
  1718.      andi.b   #~(1<<IOSERB_QUEUED),d1          ; no longer queued
  1719.      move.l   a1,cr_IOReq-Start(a5)           ; store I/O request
  1720.      ori.b      #1<<IOSERB_ACTIVE,d1              ; make it active
  1721.      move.l   IO_DATA(a1),cr_OutPtr-Start(a5)     ; get/set output ptr
  1722.      move.b   d1,IO_FLAGS(a1)
  1723.      move.l   IO_LENGTH(a1),cr_Length-Start(a5)   ; get/set output count
  1724.      ;
  1725.      ;      Process an active I/O request
  1726.      ;
  1727. 30$     move.l   SysBase(pc),a6              ; get ExecBase
  1728.      move.l   d0,a1                   ; get I/O request
  1729.      bsr.b      copyData                  ; go copy 'em
  1730.      tst.l      d0                      ; done with request?
  1731.      beq.b      9$                      ; nope, branch
  1732.      ;
  1733.      ;      the request has been satisfied, so return it.
  1734.      ;
  1735.      clr.l      cr_IOReq-Start(a5)              ; clear request
  1736.      andi.b   #~(1<<IOSERB_ACTIVE),IO_FLAGS(a1)   ; no longer active
  1737.      jsr      _LVOReplyMsg(a6)              ; return I/O
  1738. 10$     moveq      #0,d0                   ; set Z flag
  1739. 9$     move.l   (sp)+,a0
  1740.      jmp      (a0)                      ; return
  1741.      ;
  1742.      ;      Registers:
  1743.      ;      Entry:   A1        Ptr to I/O Request
  1744.      ;           A6        ExecBase
  1745.      ;      Exit:    D0        ZERO - request not done, do not reply it
  1746.      ;                NZERO - request done, reply it
  1747.      ;
  1748.      cnop 0,8 ; align for 040+
  1749. copyData:
  1750.      ;
  1751.      ;      Process an active I/O request (or fall through from above)
  1752.      ;
  1753.      move.l   a5,-(sp)                  ; save registers
  1754.      move.l   d5,-(sp)                  ; save registers
  1755.      move.l   a4,-(sp)                  ; save registers
  1756.      move.l   d4,-(sp)                  ; save registers
  1757.      move.l   a3,-(sp)                  ; save registers
  1758.      move.l   d3,-(sp)                  ; save registers
  1759.      move.l   a2,-(sp)                  ; save registers
  1760.      move.l   a1,-(sp)                  ; save registers
  1761.      move.l   d2,-(sp)                  ; save registers
  1762.      lea      Start(pc),a5                  ; get base
  1763.      move.l   a1,a4                   ; get I/O request
  1764.      ;
  1765.      move.l   i_BufOut(pc),a2              ; get current bufout ptr
  1766.      move.l   cr_OutPtr(pc),a3              ; get current output ptr
  1767.      move.l   cr_Length(pc),d2              ; get current bytes needed
  1768.      move.l   i_InCnt(pc),d3              ; get current bytes in buffer
  1769.      ;
  1770.      ;      If we don't have enough bytes to satisfy the request,
  1771.      ;      set the length to the number of bytes we do have.
  1772.      ;
  1773.      cmp.l      d2,d3                   ; enuf to satisfy request?
  1774.      bge.b      15$                      ; yep, so branch
  1775.      move.l   d3,d2                   ; # to copy = # in buffer
  1776.      bra.b      16$                      ; branch to loop entry
  1777.      ;
  1778.      ;      Start of copy loop.
  1779.      ;
  1780.      cnop 0,8 ; align for 040+
  1781. 10$     move.l   i_BufPtr(pc),a2              ; reset bufout to start
  1782.      ;
  1783.      ;      Entry point of copy loop.
  1784.      ;
  1785. 15$     move.l   d2,d3                   ; xfer # of bytes to copy
  1786. 16$
  1787.      ;
  1788.      ;      If the copy will extend past the end of the buffer, we can
  1789.      ;      only copy the number of bytes to the end this go around.
  1790.      ;
  1791.      move.l   i_BufEnd(pc),d0              ; get ptr to end of buf
  1792.      sub.l      a2,d0                   ; calc # of bytes to end
  1793.      cmp.l      d0,d3                   ; # to copy < # to end?
  1794.      blt.b      20$                      ; yep, branch
  1795.      move.l   d0,d3                   ; get bytes to end
  1796.      ;
  1797.      ;      Registers:
  1798.      ;
  1799.      ;      A2 = pointer from which data will be copied
  1800.      ;      A3 = pointer to which data will be copied
  1801.      ;      D2 = number of bytes that need to be copied
  1802.      ;      D3 = number of bytes to copy this iteration
  1803.      ;
  1804. 20$     move.l   d3,d0                   ; get length
  1805.     IFNE EOFCODE
  1806.      btst      #SERB_EOFMODE,IO_SERFLAGS(a4)       ; EOFMODE requested?
  1807.      beq.b      30$                      ; nope, just go copy
  1808.      ;
  1809.      ;      EOFMODE was specified so copy characters 1 at a time until
  1810.      ;      we hit an EOF character, the output butter has filled, or
  1811.      ;      the input buffer has drained.
  1812.      ;
  1813.      move.l   IO_TERMARRAY(a4),d4              ; get termarry (part 1)
  1814.      rol.l      #8,d4
  1815.      move.l   IO_TERMARRAY(a4),d5              ; get termarry (part 2)
  1816.      move.l   d4,a1                   ; save d4
  1817.      rol.l      #8,d5
  1818.      ;
  1819. 21$     move.b   (a2)+,d1                  ; get byte
  1820.      ; This way the term char IS copied (if term char is not copied eofmode will fail)
  1821.      move.b   d1,(a3)+                  ; put in output buffer
  1822.      ;
  1823.      cmp.b      d4,d1                   ; found term char?
  1824.      bge.b      22$                      ; possibly, branch
  1825.      rol.l      #8,d4
  1826.      cmp.b      d4,d1                   ; found term char?
  1827.      bge.b      22$                      ; possibly, branch
  1828.      rol.l      #8,d4
  1829.      cmp.b      d4,d1                   ; found term char?
  1830.      bge.b      22$                      ; possibly, branch
  1831.      rol.l      #8,d4
  1832.      cmp.b      d4,d1                   ; found term char?
  1833.      bge.b      22$                      ; possibly, branch
  1834.      move.l   d5,d4                   ; get termarry (part 2)
  1835.      cmp.b      d4,d1                   ; found term char?
  1836.      bge.b      22$                      ; possibly, branch
  1837.      rol.l      #8,d4
  1838.      cmp.b      d4,d1                   ; found term char?
  1839.      bge.b      22$                      ; possibly, branch
  1840.      rol.l      #8,d4
  1841.      cmp.b      d4,d1                   ; found term char?
  1842.      bge.b      22$                      ; possibly, branch
  1843.      rol.l      #8,d4
  1844.      cmp.b      d4,d1                   ; found term char?
  1845. 22$     beq.b      24$                      ; term char found?
  1846.      ;
  1847.      ;      Didn't find a term character, so continue with the copy loop
  1848.      ;
  1849. 23$     move.l   a1,d4                   ; get termarry (part 1)
  1850.      subq.l   #1,d0                   ; decr length counter
  1851.      bne.b      21$                      ; continue if more
  1852.      bra.b      40$                      ; done with copy, branch
  1853.      ;
  1854.      ;      We've found a termination character.
  1855.      ;
  1856.      cnop 0,8 ; align for 040+
  1857. 24$     clr.l      cr_Length-Start(a5)              ; done with request
  1858.      bra.b      50$                      ; branch
  1859.      cnop 0,8 ; align for 040+
  1860.      ENDC
  1861.      ;
  1862.      ;      EOFMODE not specified, so just do a bulk copy.
  1863.      ;
  1864.      ;      XXX POSSIBLE SPEEDUP XXX
  1865.      ;
  1866.      ;      For short copies it would be quicker to have a simple inline
  1867.      ;      loop, but what's short???  It would be different by CPU.
  1868.      ;
  1869. 30$     move.l   a3,a1                   ; where to put it
  1870.      move.l   a2,a0                   ; where to get it
  1871. ; NB: buffer size is multiple of 64bytes (not contents size)
  1872.      jsr     _LVOCopyMem(a6)    ; we use copymemquicker patch by *Art
  1873.      adda.l   d3,a2                   ; update bufout
  1874.      adda.l   d3,a3                   ; update outptr
  1875.      ;
  1876.      ;      Fall through and entered from EOFMODE loop
  1877.      ;
  1878.      ;      If the following calculation results in a value greater than
  1879.      ;      zero, then we have a buffer wrap and need to process the
  1880.      ;      remaining bytes at the beginning of the buffer.
  1881.      ;
  1882. 40$     sub.l      d3,d2                   ; calc bytes left to copy
  1883.      bgt.b      10$                      ; >0, more to copy, branch
  1884.      ;
  1885.      ;
  1886.      ;
  1887. 50$     move.l   a3,d1                   ; get outptr
  1888.      sub.l      cr_OutPtr(pc),d1              ; calc length
  1889.      move.l   a3,cr_OutPtr-Start(a5)          ; update outptr
  1890.      ;
  1891.      ;      Update output ptr and I/O request
  1892.      ;
  1893.      move.l   a2,i_BufOut-Start(a5)           ; store bufout ptr
  1894.      add.l      d1,IO_ACTUAL(a4)              ; update I/O request
  1895.      ;
  1896.      ;      Update number of bytes left in the buffer.
  1897.      ;
  1898.      sub.l      d1,i_InCnt-Start(a5)              ; calc bytes left in buffer
  1899.      ;
  1900.      ;      If the threshold becomes positive here, then, if requested,
  1901.      ;      tell the other end that it's okay to start sending more data.
  1902.      ;
  1903.      add.l      d1,i_Thresh-Start(a5)           ; calc thresh and test
  1904.      ble.b      60$                      ; <= 0, need more data, skip
  1905.      tst.l      Handshake(pc)               ; are we handshaking?
  1906.      beq.b      60$                      ; nope, skip RTS
  1907.      andi.b   #~(1<<CIAB_COMRTS),_ciabpra          ; ready to recieve more data
  1908.      ;
  1909.      ;      Set error if we've had any overruns.
  1910.      ;
  1911. 60$     tst.l      Overrun(pc)                  ; did overrun occur?
  1912.      beq.b      70$                      ; nope, branch
  1913.      clr.l      Overrun-Start(a5)              ; reset overrun flag
  1914.      move.b   #SerErr_LineErr,IO_ERROR(a4)          ; set error code
  1915.      ;
  1916.      ;      Calc number of bytes left to copy.  If the result is greater
  1917.      ;      than zero, then we have more to copy so return an incomplete
  1918.      ;      status.
  1919.      ;
  1920. 70$     moveq      #0,d0                   ; assume I/O incomplete
  1921.      sub.l      d1,cr_Length-Start(a5)          ; update length and test
  1922.      bgt.b      90$                      ; >0, more to do, branch
  1923.      ;
  1924.      ;      We've completed the I/O request either by copying the requested
  1925.      ;      of bytes or by finding an EOFMODE character, so return a "reply"
  1926.      ;      status.
  1927.      ;
  1928.      moveq      #1,d0                   ; indicate reply
  1929.      ;
  1930.      ;      Restore and exit
  1931.      ;
  1932. 90$     move.l   (sp)+,d2                  ; restore registers
  1933.      move.l   (sp)+,a1                  ; restore registers
  1934.      move.l   (sp)+,a2                  ; restore registers
  1935.      move.l   (sp)+,d3                  ; restore registers
  1936.      move.l   (sp)+,a3                  ; restore registers
  1937.      move.l   (sp)+,d4                  ; restore registers
  1938.      move.l   (sp)+,a4                  ; restore registers
  1939.      move.l   (sp)+,d5                  ; restore registers
  1940.      move.l   (sp)+,a5                  ; restore registers
  1941.      move.l   (sp)+,a0                  ; return (status in D0)
  1942.      jmp      (a0)
  1943.      ;
  1944.      ;      Align data
  1945.      ;
  1946.      CNOP      0,8
  1947.      ;
  1948.      ;
  1949.      ;
  1950. Init:
  1951.      DC.L      sizeof_Base8n1
  1952.      DC.L      funcTab
  1953.      DC.L      dataTab
  1954.      DC.L      InitRoutine
  1955.      ;
  1956.      ;
  1957.      ;
  1958. funcTab:
  1959.      DC.W      -1
  1960.      DC.W      dev_Open-funcTab
  1961.      DC.W      dev_Close-funcTab
  1962.      DC.W      dev_Expunge-funcTab
  1963.      DC.W      dev_Null-funcTab
  1964.      DC.W      dev_BeginIO-funcTab
  1965.      DC.W      dev_AbortIO-funcTab
  1966.      DC.W      -1
  1967.      ;
  1968.      ;
  1969.      ;
  1970. dataTab:
  1971.      INITBYTE LN_TYPE,NT_DEVICE
  1972.      INITLONG LN_NAME,Name
  1973.      INITBYTE LIB_FLAGS,LIBF_SUMUSED|LIBF_CHANGED
  1974.      INITWORD LIB_VERSION,VERSION
  1975.      INITWORD LIB_REVISION,REVISION
  1976.      INITLONG LIB_IDSTRING,IdString
  1977.      DC.W      0
  1978.      ;
  1979.      ;      String Constants
  1980.      ;
  1981. miscresource:
  1982.      DC.B      "misc.resource",0
  1983. timerdevice:
  1984.      DC.B      "timer.device",0
  1985. intuitlib:
  1986.      DC.B      "intuition.library",0
  1987. Name:
  1988.      DC.B      "8n1.device",0
  1989. IdString:
  1990.      VSTRING
  1991.      ;
  1992.      ;      End of checksummed area.  (Realigns data too!)
  1993.      ;
  1994. ENDTag:
  1995.      CNOP      0,8
  1996.      ;
  1997.      ;      Global SysBase (Use instead of AbsExecBase for speed)
  1998.      ;
  1999. SysBase:
  2000.      DC.L      0
  2001.      ;
  2002.      ;      Internal buffer tracking (DO NOT CHANGE THE ORDER!!!!)
  2003.      ;
  2004. i_BufPtr:
  2005.      DC.L      0
  2006. i_BufIn:
  2007.      DC.L      0
  2008. i_BufOut:
  2009.      DC.L      0
  2010. i_BufEnd:
  2011.      DC.L      0
  2012. i_InCnt:
  2013.      DC.L      0
  2014. i_Thresh:
  2015.      DC.L      0
  2016.      ;
  2017.      ;      Used while processing a read request.
  2018.      ;
  2019. cr_IOReq:
  2020.      DC.L      0
  2021. cr_OutPtr:
  2022.      DC.L      0
  2023. cr_Length:
  2024.      DC.L      0
  2025.      ;
  2026.      ;      List head for read requests
  2027.      ;
  2028. readQ:
  2029.      DC.L      readQ+MLH_TAIL
  2030.      DC.L      0
  2031.      DC.L      readQ
  2032.      ;
  2033.      ;      Write control.
  2034.      ;
  2035. cw_Length:
  2036.      DC.L      0
  2037. cw_Buffer:
  2038.      DC.L      0
  2039. cw_IOReq:
  2040.      DC.L      0
  2041.      ;
  2042.      ;      List head for write requests
  2043.      ;
  2044. writeQ:
  2045.      DC.L      writeQ+MLH_TAIL
  2046.      DC.L      0
  2047.      DC.L      writeQ
  2048.      ;
  2049.      ;
  2050.      ;
  2051. timerPort:
  2052.      DC.L      0                      ; LN_SUCC
  2053.      DC.L      0                      ; LN_PRED
  2054.      DC.B      NT_MSGPORT                  ; LN_TYPE
  2055.      DC.B      0                      ; LN_PRI
  2056.      DC.L      0                      ; LN_NAME
  2057.      DC.B      3                      ; MP_FLAGS (undoc'ed)
  2058.      DC.B      0                      ; MP_SIGBIT
  2059.      DC.L      timerRtn                  ; MP_SIGTASK
  2060.      DC.L      timerPort+MP_MSGLIST+LH_TAIL          ; LH_HEAD
  2061.      DC.L      0                      ; LH_TAIL
  2062.      DC.L      timerPort+MP_MSGLIST              ; LH_TAILPRED
  2063.      DC.B      0                      ; LH_TYPE
  2064.      DC.B      0                      ; LH_pad
  2065.      DC.W      0                      ; long align
  2066.      ;
  2067.      ;
  2068.      ;
  2069. timerReq:
  2070.      DC.L      0                      ; LN_SUCC
  2071.      DC.L      0                      ; LN_PRED
  2072.      DC.B      NT_MESSAGE                  ; LN_TYPE
  2073.      DC.B      0                      ; LN_PRI
  2074.      DC.L      0                      ; LN_NAME
  2075.      DC.L      timerPort                  ; MN_REPLYPORT
  2076.      DC.W      IOTV_SIZE                  ; MN_LENGTH
  2077.      DC.L      0                      ; IO_DEVICE
  2078.      DC.L      0                      ; IO_UNIT
  2079.      DC.W      TR_ADDREQUEST               ; IO_COMMAND
  2080.      DC.B      0                      ; IO_FLAGS
  2081.      DC.B      0                      ; IO_ERROR
  2082.      DC.L      0                      ; TV_SECS
  2083.      DC.L      0                      ; TV_MICROS
  2084.      ;
  2085.      ;
  2086.      ;
  2087. VBInterrupt:
  2088.      DC.L      0                      ; LN_SUCC
  2089.      DC.L      0                      ; LN_PRED
  2090.      DC.B      NT_INTERRUPT                  ; LN_TYPE
  2091.      DC.B      0                      ; LN_PRI
  2092.      DC.L      Name                      ; LN_NAME
  2093.      DC.L      readQ                   ; IS_DATA
  2094.      DC.L      level2                  ; IS_CODE
  2095.      ;
  2096.      ;      Global flags
  2097.      ;
  2098.      CNOP      0,4
  2099. Overrun:
  2100.      DC.L      0
  2101. Handshake:
  2102.      DC.L      1
  2103. disableRead:
  2104.      DC.L      -1
  2105. cmdlist:
  2106.      dc.w      CMD_RESET
  2107.      dc.w      CMD_READ
  2108.      dc.w      CMD_WRITE
  2109.      dc.w      CMD_CLEAR
  2110.      dc.w      CMD_FLUSH
  2111.      dc.w      SDCMD_QUERY
  2112.      dc.w      SDCMD_BREAK
  2113.      dc.w      SDCMD_SETPARAMS
  2114.      dc.w      NSCMD_DEVICEQUERY
  2115.      dc.w      0
  2116.      ;
  2117.      ;
  2118.      ;
  2119.      END
  2120.  
  2121.